Use SeekBar in Listview item - java

I have a listview that has a custom adapter with a SeekBar. The view inflate fine, but when I touch the SeekBar and try to change the value, it does not responde the click, do nothing, how can I solve it?
list_itemx.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:orientation="horizontal">
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:clickable="false"
android:focusable="false"/>
<SeekBar
android:id="#+id/progress"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="10dp"
android:layout_marginStart="10dp"
android:max="100"
android:progressDrawable="#drawable/seekbar_progress"
android:thumb="#drawable/seekbar_thumb"
android:clickable="false"
android:focusable="false"
/>
</LinearLayout>
my getView function inside the adapter
LayoutInflater layoutInflater = LayoutInflater.from(parent.getContext());
View view;
if (convertView == null){
view = layoutInflater.inflate(R.layout.dispositivo_list_item, parent, false);
}else{
view = convertView;
}
final int mPosition = position;
holder = new ViewHolder(view);
holder.progress.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
#Override
public void onProgressChanged(SeekBar seekBar, int value, boolean b) {
changeProgress(mPosition,value);
}
#Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
#Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
});
holder.name.setClickable(false);
holder.name.setFocusable(false);
holder.progress.setFocusable(false);
holder.mView.setClickable(false);
return view;
}
Edit: I found the solution. I had a notifyDataSetChanged in a function that I call inside the callback. That's what was blocking the SeekBar. Thanks for the help anyway

Related

Android: Clicklistener on parent not working when clicked on child

I have a cardview, with some widgets in, and a recycler view inside the card view. The cardview is the parent.
I want it to be that when anywhere in the cardview is clicked, the event to happen. However, now only when the top part of the card view is clicked it triggers, but not when I click on the recycler view.
I tried setting clickable in the recyclerview to false, and it doesn't work.
Here is my xml.
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="#+id/card_view_today"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_margin="10dp"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp"
android:padding="5dp"
android:clickable="true"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dp"
android:clickable="false"
android:gravity="center_vertical"
>
<ImageView
android:layout_width="20dp"
android:layout_marginLeft="5dp"
android:layout_height="20dp"
android:clickable="false"
android:src="#drawable/today_icon_small"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:text="I still need to have today"
android:layout_margin="5dp"/>
</LinearLayout>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/today_recycler_view_summary"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:clickable="false"
android:paddingBottom="10dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
</android.support.v7.widget.CardView>
And here is the code of the click listener I do on the activity oncreate():
todayCardView = (CardView) findViewById(R.id.card_view_today);
todayCardView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Log.d(TAG, "Today card tapped");
Intent intent = new Intent(MainActivity.this, TodayActivity.class);
startActivity(intent);
}
});
As requsted, here is my adapter and view holder, for the recycler view, which is in the card view.
public class SummaryRecyclerViewAdapter extends RecyclerView.Adapter<SummaryRecyclerViewAdapter.ViewHolder> {
String[] todaysItems;
public SummaryRecyclerViewAdapter(String[] todaysItems) {
this.todaysItems = todaysItems;
}
#Override
public SummaryRecyclerViewAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.recycler_view_chip,parent,false);
return new SummaryRecyclerViewAdapter.ViewHolder(view);
}
#Override
public void onBindViewHolder(SummaryRecyclerViewAdapter.ViewHolder holder, int position) {
holder.textView.setText(todaysItems[position]);
}
#Override
public int getItemCount() {
return todaysItems.length;
}
public static class ViewHolder extends RecyclerView.ViewHolder{
public TextView textView;
public ViewHolder(View v){
super(v);
textView = (TextView)v.findViewById(R.id.chip_text_view);
}
}
}
Add this for the recycler view .This makes sure that the child view will not handle the touch event .
#Override
public boolean onTouchEvent(MotionEvent event) {
super.onTouchEvent(event);
return false;
}
Read this article to better understand the touch input flow .
http://balpha.de/2013/07/android-development-what-i-wish-i-had-known-earlier/

Android ListView OnClickListener

I need to add a code responsible for action when one row from my list is clicked. I don't know if it should be OnItemClickListener or OnClickListener and how&where to write it. My app is with view holder. Here is my code:
public class JobListAdapter extends ArrayAdapter<String> {
private LayoutInflater mInflater;
public static class WorkViewHolder {
public TextView mJob;
public ImageView mImageAndroKorpo;
}
public JobListAdapter(Context mContext, List<String> mDane) {
super(mContext, R.layout.list_element_job, mDane);
this.mInflater = (LayoutInflater) mContext
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
WorkViewHolder mHolder;
if(convertView == null) {
convertView = mInflater.inflate(R.layout.list_element_job, parent, false);
mHolder = new WorkViewHolder();
TextView mJobsName = (TextView) convertView.findViewById(R.id.nazwa_oferty);
ImageView mImageAndroKorpo = (ImageView)convertView.findViewById(R.id.list_image);
mHolder.mJob = mJobsName;
mHolder.mImageAndroKorpo = mImageAndroKorpo;
convertView.setTag(mHolder);
} else {
mHolder = (WorkViewHolder)convertView.getTag();
}
final String mWorkPosition = getItem(position);
mHolder.mJob.setText(mWorkPosition);
mHolder.mJob.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// Here?
}
});
return convertView;
}
}
I added code where I think it should be placed. Is it ok? OnItem or OnClick? And how to use item position?
My list_element_job.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:padding="10dp"
<CheckBox
android:id="#+id/list_checkbox"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="#+id/list_image"
android:src="#drawable/android_white_piece"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_width="1dp"
android:layout_height="1dp"/>
<TextView
android:text=""
android:background="#drawable/android_korpo_transparent3"
android:textStyle="bold"
android:textColor="#android:color/black"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:gravity="left"
android:layout_toLeftOf="#id/list_image"
android:layout_width="0dp"
android:textSize="7pt"
android:layout_height="wrap_content"
android:id="#+id/nazwa_oferty"/>
<TextView
android:text="Details..."
android:background="#android:color/white"
android:clickable="true"
android:focusable="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_below="#id/nazwa_oferty"
android:textSize="6pt"
android:textColor="#android:color/darker_gray"/>
</RelativeLayout>
Please help me somehow :)
Just remove the focus for the checkbox in xml like below:
<CheckBox
android:id="#+id/list_checkbox"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
because of check box focus list item click listeners wont work.
Just remove onClick from your adapter class. And add OnItemClickListener to your ListView
example:
JobListAdapter jobListAdapter = new JobListAdapter (...);
listView.setAdapter(jobListAdapter);
listView..setOnItemClickListener(new OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
}
});

ListFragment OnItemClickListener

I have a list fragment displaying my custom list items which consist of a relative layout containing images and text etc.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#color/main_background"
android:paddingLeft="20dp"
android:paddingTop="10dp"
android:paddingRight="20dp"
android:paddingBottom="10dp"
android:descendantFocusability="blocksDescendants" >
<ImageView
android:id="#+id/source_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:background="#color/black"
android:layout_alignParentLeft="true"
android:contentDescription="#string/info" />
<TextView
android:id="#+id/item_description"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white"
android:textStyle="bold"
android:layout_toRightOf="#+id/source_image"
android:textColor="#color/black"
android:paddingRight="5dp"
android:paddingTop="5dp"
android:paddingBottom="5dp"
android:paddingLeft="5dp"
android:textAlignment="center"
android:text="#string/item_desc" />
<ImageView
android:id="#+id/arrow_image"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_marginRight="30dp"
android:layout_alignParentRight="true"
android:contentDescription="#string/info"
android:src="#drawable/arrow_right" />
<HorizontalScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:scrollbars="none"
android:layout_centerInParent="true"
android:background="#color/main_background"
android:layout_below="#+id/item_description">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#color/white"
android:layout_gravity="fill_horizontal"
android:layout_marginRight="20dp"
android:padding="5dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/item_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/info"
android:src="#drawable/chameleon" />
<ImageView
android:id="#+id/item_image2"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/info"
android:gravity="center"
android:src="#drawable/chameleon" />
<ImageView
android:id="#+id/item_image3"
android:paddingLeft="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:contentDescription="#string/info"
android:gravity="center"
android:src="#drawable/chameleon" />
</LinearLayout>
</HorizontalScrollView>
</RelativeLayout>
I am trying to set up an OnItemClickListener so when the user clicks anywhere on the list item, a new Intent is started.
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
//Populate list view with array objects
adapter = new HomeListItemAdapter(items, getActivity());
listView = getListView();
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
Toast toast = Toast.makeText(listView.getContext(), "CLICKED", Toast.LENGTH_SHORT);
toast.show();
}
});
}
I am attempting this as shown above but can't seem to get the OnItemClickListener to work (just testing with Toast instead of Intent for now). Where am I going wrong?
Thanks
EDIT: Added custom list adapter code
public class HomeListItemAdapter extends BaseAdapter {
private List<HomeListItem> items;
private Context context;
private int numItems = 0;
public HomeListItemAdapter(final List<HomeListItem> items, Context context) {
this.items = items;
this.context = context;
this.numItems = items.size();
}
public int getCount() {
return numItems;
}
public HomeListItem getItem(int position) {
return items.get(position);
}
public long getItemId(int position) {
return 0;
}
public View getView(int position, View convertView, ViewGroup parent) {
// Get the current list item
final HomeListItem item = items.get(position);
// Get the layout for the list item
final RelativeLayout itemLayout = (RelativeLayout) LayoutInflater.from(context).inflate(R.layout.list_item, parent, false);
// Set the the item picture(s)
ImageView itemImage = (ImageView) itemLayout.findViewById(R.id.item_image);
itemImage.setImageDrawable(item.getItemPic());
//Set the profile picture / source picture
ImageView sourceImage = (ImageView) itemLayout.findViewById(R.id.source_image);
sourceImage.setImageDrawable(item.getSourcePic());
// Set the text label as defined in our list item
TextView itemDesc = (TextView) itemLayout.findViewById(R.id.item_description);
AssetManager am = context.getAssets();
Typeface font = Typeface.createFromAsset(am, "Raleway-Thin.ttf");
itemDesc.setTypeface(font);
itemDesc.setText(item.getText());
return itemLayout;
}
}
Try extending ListFragment (instead of just a normal Fragment). Then you can override onListItemClicked:
public void onListItemClick(ListView l, View v, int pos, long id)
This gives you the list, view, position, and id, so you should be able to do whatever you need.
Could you try setting the HozizontalScrollView to not get focus with the XML attribute
android:focusable="false"
If you have a TextView inside the row then that will take focus when the row is clicked. This will mean that onListItemClick is not called. You either need to have an OnClickListener on the TextView or remove focus from the TextView.
See ListFragment OnListItemClick not being called
Try this sample project for costum ListFragment. It is a very good example with a costum ListFragment showing 2 types of views for phone and tablets.
http://s000.tinyupload.com/index.php?file_id=09444774931653041243
Courtsey
http://jcrazyandroider.blogspot.in/2015/01/download-links.html

Adding Custom Header to List Fragment in Android

I am trying to add a custom header that isnt clickable but will have a checkbox that will "check all" checkboxes under it.
This is my List Fragment
public class AssesmentListFragment extends ListFragment {
private static String BUNDLE_KEY_APPLICATION = "LIST_ITEM";
FastAssesmentListAdapter adapter;
View listHeader;
public AssesmentListFragment() {}
public AssesmentListFragment(Data[] data) {
}
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Data[] assestments = {new Data("Assesment ID","Name", "Date"), new Data("123456", "Assestment 2", "9/12/12"),
new Data("345672", "Assesment 3", "9/13/12"), new Data("566893", "Assesment 4", "9/14/12")};
//This is the part that makes the app crash
View header = getActivity().getLayoutInflater().inflate(R.layout.list_adapter_assesments, null);
ListView listView = getListView();
listView.addHeaderView(header);
adapter = new FastAssesmentListAdapter(getActivity(), assestments);
setListAdapter(adapter);
updateList(assestments);
}
#Override
public void onActivityCreated(Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
}
private void updateList(Data[] assestments) {
// NOTE: addAll is not being used to support pre-honeycomb devices
synchronized(adapter) {
adapter.clear();
adapter.addAll(assestments);
adapter.notifyDataSetChanged();
}
}
#Override
public void onListItemClick(ListView parentView, View selectedItemView, int position, long id) {
String model = (String) parentView.getItemAtPosition(position);
((FacilityActivity) getActivity()).onItemSelected(model);
}
#Override
public void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
//outState.putInt("curChoice", mCurCheckPosition);
}
}
This is the layout I am trying to use for header
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingRight="10dp"
android:orientation="horizontal">
<TextView android:id="#+id/adapter_header_textview_column1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Assesment ID" />
<TextView android:id="#+id/adapter_header_textview_column2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Name" />
<TextView android:id="#+id/adapter_header_textview_column3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textColor="#color/defaultTextColor"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="28sp"
android:text="Date"/>
<CheckBox
android:id="#+id/header_check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:color="#color/defaultTextColor"
android:layout_weight=".5"
android:gravity="center" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="5dp"
android:background="#color/BPGreenColor" />
<ListView
android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
</LinearLayout>
Then this is the array adapter I am using:
public class FastAssesmentListAdapter extends ArrayAdapter<Data> {
private static int LAYOUT_ID = R.layout.list_adapter_with_checkbox_three_column;
private final Data[] assesments;
private final Context context;
LinearLayout listHeader;
static class ViewHolder {
protected TextView column1;
protected TextView column2;
protected TextView column3;
protected CheckBox checkbox;
}
public FastAssesmentListAdapter(Context context, Data[] assesments) {
super(context, LAYOUT_ID, assesments);
this.context = context;
this.assesments = assesments;
}
//ListFragment and array adapter will automatically call this over and over to auto populate the list
#Override
public View getView(int position, View convertView, ViewGroup parent) {
final Data item = getItem(position);
// Formulate row view (create if it does not exist yet)
View view = convertView;
if(view == null) {
LayoutInflater inflater = ((Activity) getContext()).getLayoutInflater();
view = inflater.inflate(LAYOUT_ID, null);
final ViewHolder viewHolder = new ViewHolder();
viewHolder.column1 = (TextView) view.findViewById(R.id.adapter_textview_column1);
viewHolder.column2 = (TextView) view.findViewById(R.id.adapter_textview_column2);
viewHolder.column3 = (TextView) view.findViewById(R.id.adapter_textview_column3);
viewHolder.checkbox = (CheckBox) view.findViewById(R.id.check_box);
view.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getContext(), "Clicked",
Toast.LENGTH_SHORT).show();
Intent intent = new Intent(getContext(), FacilityActivity.class);
getContext().startActivity(intent);
}
});
if(viewHolder.checkbox != null) {
viewHolder.checkbox.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
if(isChecked) {
item.setSelected(isChecked);
Toast.makeText(getContext(), "Checked",
Toast.LENGTH_SHORT).show();
}
}
});
}
view.setTag(viewHolder);
viewHolder.checkbox.setTag(position);
}
ViewHolder viewHolder = (ViewHolder) view.getTag();
viewHolder.checkbox.setTag(position);
viewHolder.column1.setText(item.getColumn1());
viewHolder.column2.setText(item.getColumn2());
viewHolder.column3.setText(item.getColumn3());
viewHolder.checkbox.setChecked(item.isSelected());
return view;
}
}
on a side note, the onlistitemclicked in the fragment doesnt work, i have to set a listener in the adapter and then it works. any ideas on that? but mainly I need to figure out how to use a custom header and custom rows in the list view. Here is the layout for the rows
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:paddingLeft="25dp"
android:paddingRight="10dp"
android:orientation="horizontal">
<TextView android:id="#+id/adapter_textview_column1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<TextView android:id="#+id/adapter_textview_column2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<TextView android:id="#+id/adapter_textview_column3"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="3"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textSize="25sp" />
<CheckBox
android:id="#+id/check_box"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:gravity="center" />
</LinearLayout>

Android Listview and textWatcher

Good afternoon everybody :)
I have a listview for adding goals (not important :p). the listview's child has some textviews and edittextboxes, where the user can fill in its information.
I have a Textwatcher which checks whether the text in one of the listview's childs has changed, so the data can be written to the class in the array off the listview + a global array (for passing data between activety's, but this is also not important).
Now my problem is, when I add an Item to the list, the text of all the previous existing items in edittext 'discription' changes to the text of newly added Item. For example when i have 1 Item in the listview that says 'test' and I add a new one to the list that says 'this is a new test' >> Both change to 'this is a new test'. I debugged the program a lot and noticed that in the end (after adding the new item), the program will go trough the textwatcher with 's' = 'this is a new test' and position = '0'. This probably causes the text of the first one to change.. But I don't understand why this is happening.
Can somebody help me?
this is my listview:
class listViewAdapter extends BaseAdapter {
private Context context;
private ArrayList<Goals> list;
public listViewAdapter(final Context context, ArrayList<Goals> list) {
this.context = context;
this.list = list;
}
#Override
public int getCount() {
return list.size();
}
#Override
public Object getItem(int position) {
return list.get(position);
}
#Override
public long getItemId(int position) {
return position;
}
public void synchronise(){
geldclass.setGoals_list(this.list);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
if (convertView == null) {
final LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.goal_item, parent,
false);
}
Goals goal = (Goals) getItem(position);
final EditText txtdiscription = (EditText) convertView.findViewById(R.id.editDiscription);
txtdiscription.setText(goal.getDiscription());
txtdiscription.addTextChangedListener(new textWatcher(txtdiscription, position));
final EditText txtgoal = (EditText) convertView
.findViewById(R.id.editGoal);
txtgoal.addTextChangedListener(new textWatcher(txtgoal, position));
final EditText txtfrom = (EditText) convertView
.findViewById(R.id.editFrom);
txtfrom.addTextChangedListener(new textWatcher(txtfrom, position));
final EditText txtto = (EditText) convertView
.findViewById(R.id.editto);
txtto.addTextChangedListener(new textWatcher(txtto, position));
final CheckBox check_date = (CheckBox) convertView
.findViewById(R.id.check_enable_date);
check_date
.setOnCheckedChangeListener(new OnCheckedChangeListener() {
#Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {
}
});
return convertView;
}
private class textWatcher implements TextWatcher {
private View view;
private int position;
private textWatcher(View view, int position) {
this.view = view;
this.position = position;
}
#Override
public void afterTextChanged(Editable s) {
switch (view.getId()) {
case R.id.editDiscription:
list.get(position).setDiscription(s.toString());
synchronise();
break;
case R.id.editGoal:
list.get(position).setGoalvalue(Integer.parseInt(s.toString()));
synchronise();
break;
}
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
// TODO Auto-generated method stub
}
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
// TODO Auto-generated method stub
}
}
}
this is my goal child item in xml:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TableRow
android:id="#+id/tableRow1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textDiscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/name"
android:textSize="15dp"
android:width="80dp" />
<EditText
android:id="#+id/editDiscription"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:width="120dp" >
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow3"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textGoal"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/goal"
android:textSize="15dp" />
<EditText
android:id="#+id/editGoal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:width="200dp" >
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow2"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<CheckBox
android:id="#+id/check_enable_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/from"
android:textSize="15dp" />
<EditText
android:id="#+id/editFrom"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10" >
</EditText>
</TableRow>
<TableRow
android:id="#+id/tableRow4"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/textfrom"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="right"
android:text="#string/to"
android:textSize="15dp" />
<EditText
android:id="#+id/editto"
android:enabled="false"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="date"
android:ems="10" >
</EditText>
</TableRow>
</TableLayout>
And here is where I add the Items (don't pay attention to 'geldclass'.. Its a global class where the global array is stored):
public void onClick(View v) {
Goals goal = new Goals("this is a new test");
geldclass.addGoals(goal);
goal_adapter = new listViewAdapter(GoalManager.this, geldclass.getGoals_list());
goal_list.setAdapter(goal_adapter);
}
public void onClick(View v) {
Goals goal = new Goals("this is a new test");
geldclass.addGoals(goal);
goal_adapter = new listViewAdapter(GoalManager.this, geldclass.getGoals_list());
goal_list.setAdapter(goal_adapter);
}
should be changed to
public void onClick(View v) {
Goals goal = new Goals("this is a new test");
geldclass.addGoals(goal);
goal_adapter.setNotifyDatasetChanges();
}
calling the setNotifyDatasetChanges() make the Adapter to refresh the listView with the new changed data in its list, i'm assuming that the geldclass.getGoals_list() is the same list that you initialized the Adapter before.

Categories

Resources