I have a button in each list item of list view. In that button click event i have some codes to run. In click event im showing the progress dialog before the code runs. but its not getting shown. After all the codes in click event completes in the end progress dialog gets shown. Plz help me.
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
TheListViewM = (ListView) findViewById(R.id.lvItems);
ImageAdapter anImageAdapterM =new ImageAdapter(this);
TheListViewM.setAdapter(anImageAdapterM);
}
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
if (ConvertViewP == null) {
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
}
TextView textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
textView1.setText("asdfg");
final Spinner spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spQuantity.setAdapter(QuantityAdapter1);
Button btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
Try this one.
public class ImageAdapter extends BaseAdapter {
private Context mContextL;
public ImageAdapter(Context contextP) {
mContextL = contextP;
}
public int getCount() {
return ItemList.GetLength();
}
public Object getItem(int PositionP) {
return ItemList.GetObject(PositionP);
}
public long getItemId(int PositionP) {
return PositionP;
}
class ViewHolder {
Button btn1;
TextView textView1;
Spinner spQuantity;
}
public View getView(final int PositionP, View ConvertViewP, ViewGroup ParentP) {
ViewHolder holder;
if (ConvertViewP == null) {
holder = new ViewHolder();
LayoutInflater inflater = (LayoutInflater) mContextL.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
ConvertViewP = inflater.inflate(R.layout.add_cart_row_layout, ParentP, false);
holder.textView1 = (TextView) ConvertViewP.findViewById(R.id.tvName);
holder.spQuantity = (Spinner) ConvertViewP.findViewById(R.id.spQuantity);
holder.btn1 = (Button) ConvertViewP.findViewById(R.id.btn1);
ConvertViewP.setTag(holder);
}
else{
holder = (ViewHolder) ConvertViewP.getTag();
}
holder.textView1.setText("asdfg");
holder.spQuantity.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> Parent, View view,
int pos, long id) {
ProgressDialog aProgressDialogL = new ProgressDialog(mContextL);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show();
//Processiing codes
}
#Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
ArrayAdapter<String> QuantityAdapter1 = new ArrayAdapter<String>(mContextL,android.R.layout.simple_spinner_item, QuantityList);
QuantityAdapter1.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spQuantity.setAdapter(QuantityAdapter1);
holder.btn1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
ProgressDialog aProgressDialogL = new ProgressDialog(activity1.this);
aProgressDialogL.setMessage("Loading...");
aProgressDialogL.show(); }
});
return ConvertViewP;
}
}
Related
Adapter Class:
public List<TSPDataModel> employeeData;
private Context mContext;
private LayoutInflater mInflater;
RadioGroup radiogroupbutton;
String[] data = {"Document not clear","Adress is not Visibile","Photo is not pasted","Signature is not Avilable"};
String value;
public TSPListDocumentadapter(Context context, int textViewResourceId,
List<TSPDataModel> objects)
{
this.employeeData = objects;
this.mContext = context;
mInflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
#Override
public View getView(final int position, View convertView, ViewGroup parent) {
final ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.tspdocumentlistitem, null);
holder.relatvie1=(RelativeLayout)convertView.findViewById(R.id.relatvie1);
holder.txtName = (TextView) convertView.findViewById(R.id.textView1);
holder.accecpt = (ImageView) convertView.findViewById(R.id.imageButton);
holder.reject = (ImageView) convertView.findViewById(R.id.imageButton2);
holder.statustextview = (TextView) convertView.findViewById(R.id.statustextview);
holder.poaedittext=(TextView) convertView.findViewById(R.id.poieditext);
holder.poaedittext=(TextView)convertView.findViewById(R.id.poaedittext);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.txtName.setText(employeeData.get(position).getName());
holder.poaedittext.setText(employeeData.get(position).getPoa());
holder.accecpt.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
holder.statustextview.setText("Accepted");
employeeData.get(position).setSelected(true);
employeeData.get(position).getOrderId();
holder.relatvie1.setBackgroundResource(R.color.acceptedcolor);
}
});
holder.reject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showdilog();
holder.statustextview.setText("Rejected");
employeeData.get(position).setSelected(false);
employeeData.get(position).setReasone(value);
holder.relatvie1.setBackgroundResource(R.color.rejectcolor);
}
});
return convertView;
}
static class ViewHolder {
TextView txtName;
ImageView reject;
ImageView accecpt;
TextView statustextview;
TextView poiedittext;
TextView poaedittext;
RelativeLayout relatvie1;
}
public int getCount() {
return employeeData.size();
}
public TSPDataModel getItem(int position) {
return employeeData.get(position);
}
public long getItemId(int position) {
return 0;
}
public void showdilog() {
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.layoutpopup);
radiogroupbutton = (RadioGroup) dialog.findViewById(R.id.radio_gp_day);
ListView listview = (ListView) dialog.findViewById(R.id.radio_slot_list);
Button setbutton = (Button) dialog.findViewById(R.id.setbutton);
List<String> list = new ArrayList<String>();
ArrayAdapter<String> myadpter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_single_choice, data);
for (int i = 0; i < data.length; i++) {
list.add(data[i]);
}
listview.setAdapter(myadpter);
listview.setItemsCanFocus(false);
listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
value = data[position];
Toast.makeText(mContext, value, Toast.LENGTH_LONG).show();
}
});
setbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(mContext, value, Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
dialog.show();
}
This Button click in my actvity class :
#Override
public void onClick(View view) {
if (view.getId() == R.id.button1) {
try {
List<TSPDataModel> empData = adapter.employeeData;
System.out.println("Total Size :" + empData.size());
for (TSPDataModel employeeModel : empData) {
if (employeeModel.isSelected()) {
Toast.makeText(TSPDocumentListActvity.this, employeeModel.getName(), Toast.LENGTH_LONG).show();
} else {
String Reasonse= employeeModel.getresonse() ;
Toast.makeText(TSPDocumentListActvity.this, "false" + employeeModel.getName(), Toast.LENGTH_LONG).show();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
First i Print data in Listview then each list view item there is accept and reject Button is there when we click on accept then no alert will asked only reject button reason will ask which is come on listitem on popup i want to get that selected reason on Button click in actvity but i always get null value please help me where i am doing wrong
change your reject button and showDialog code to
holder.reject.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showdilog(position);
holder.statustextview.setText("Rejected");
holder.relatvie1.setBackgroundResource(R.color.rejectcolor);
}
});
and showDualog to
public void showdilog(int list_position) {
final Dialog dialog = new Dialog(mContext);
dialog.setContentView(R.layout.layoutpopup);
radiogroupbutton = (RadioGroup) dialog.findViewById(R.id.radio_gp_day);
ListView listview = (ListView) dialog.findViewById(R.id.radio_slot_list);
Button setbutton = (Button) dialog.findViewById(R.id.setbutton);
List<String> list = new ArrayList<String>();
ArrayAdapter<String> myadpter = new ArrayAdapter<String>(mContext, android.R.layout.simple_list_item_single_choice, data);
for (int i = 0; i < data.length; i++) {
list.add(data[i]);
}
listview.setAdapter(myadpter);
listview.setItemsCanFocus(false);
listview.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
listview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
value = data[position];
employeeData.get(list_position).setSelected(false);
employeeData.get(list_position).setReasone(value);
Toast.makeText(mContext, value, Toast.LENGTH_LONG).show();
}
});
setbutton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Toast.makeText(mContext, value, Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
dialog.show();
}
I am a beginner to Android. Now I am working with ListView using custom adapter and custom view. Custom adapter is created as into a separate file. But inside my custom adapter, I set up a click listener for a button of the layout of the list view row. But my problem is how can I update items of the adapter inside event listener that is created inside the custom adapter.
This is my Listview Fragment:
public class TaskListFragment extends Fragment {
private DatabaseHelper dbHelper;
private TextView taskTitle;
private ListView taskListView;
private ArrayAdapter adapter;
private ArrayList<Task> items;
private int optionFocusedItemIndex;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
dbHelper = new DatabaseHelper(getActivity());
View view= inflater.inflate(R.layout.task_list, container, false);
taskTitle = (TextView)view.findViewById(R.id.task_textview);
taskListView = (ListView)view.findViewById(R.id.listViewTaskList);
int type = getArguments().getInt("type");
switch (type){
case R.integer.task_list_all:
items = dbHelper.getAllTasks();
adapter = new TaskListAdapter(getActivity(),items);
taskListView.setAdapter(adapter);
taskTitle.setText("All tasks");
break;
}
taskListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
int tagId = Integer.valueOf(view.getTag().toString());
optionFocusedItemIndex = position;
showOptionDialog(tagId);
return true;
}
});
return view;
}
public void showOptionDialog(final int id)
{
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View view = layoutInflater.inflate(R.layout.row_option_dialog, null);
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
Button doneBtn = (Button)view.findViewById(R.id.btn_row_option_done);
doneBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.markAsDone(id);
refreshListView();
alertDialog.cancel();
Toast.makeText(getActivity().getBaseContext(),"Marked as done",Toast.LENGTH_SHORT).show();
}
});
Button editBtn = (Button)view.findViewById(R.id.btn_row_option_edit);
editBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MainActivity activity = (MainActivity)getActivity();
activity.replaceEditTaskFragment(id);
alertDialog.cancel();
}
});
Button deleteBtn = (Button)view.findViewById(R.id.btn_row_option_delete);
deleteBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.deleteTask(id);
items.remove(optionFocusedItemIndex);
adapter.notifyDataSetChanged();
Toast.makeText(getActivity().getBaseContext(),"Task deleted",Toast.LENGTH_SHORT).show();
alertDialog.cancel();
}
});
Button cancelBtn = (Button)view.findViewById(R.id.btn_row_option_cancel);
cancelBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.cancel();
}
});
alertDialog.setView(view);
alertDialog.show();
}
public void refreshListView()
{
if(items!=null)
{
Task taskOld = items.get(optionFocusedItemIndex);
if(taskOld!=null)
{
taskOld.setDone(true);
items.set(optionFocusedItemIndex, taskOld);
adapter.notifyDataSetChanged();
}
}
}
}
Inside the fragment, when I click the done button listView adapter is updated properly and it is working find. Done button is inside the AlertDialog box that appear when long click on one of the rows of list view.
The problem is here.
This is my custom adapter class:
public class TaskListAdapter extends ArrayAdapter<Task> {
private final Context context;
private final ArrayList<Task> values;
private final DatabaseHelper dbHelper;
public TaskListAdapter(Context context,ArrayList<Task> values)
{
super(context,-1,values);
this.context = context;
this.values = values;
this.dbHelper = new DatabaseHelper(context.getApplicationContext());
}
#Override
public View getView(final int position,View convertView,ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.task_list_row,parent, false);
rowView.setTag(values.get(position).getId());
TextView rowDescription = (TextView)rowView.findViewById(R.id.task_row_description);
rowDescription.setText(values.get(position).getDescription());
ImageView rowStatusIcon = (ImageView)rowView.findViewById(R.id.task_row_status_icon);
Long currentDateMillSec= System.currentTimeMillis();
Long dateMillSec = CommonHelper.convertStrDateToMilSec(values.get(position).getDate());//(date==null)?0:date.getTime();
if(values.get(position).getDone()==Boolean.TRUE)
{
rowStatusIcon.setImageResource(R.drawable.done_icon);
}
else if(dateMillSec>0 && dateMillSec<currentDateMillSec)
{
rowStatusIcon.setImageResource(R.drawable.failed_icon);
}
else{
rowStatusIcon.setImageResource(R.drawable.todo_icon);
}
TextView dateTf = (TextView)rowView.findViewById(R.id.task_row_date);
dateTf.setText(values.get(position).getDate());
Button doneBtn = (Button)rowView.findViewById(R.id.task_row_done_btn);
doneBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.markAsDone(values.get(position).getId());
//How can I update the listview items here ?
}
});
return rowView;
}
}
So how can I update the listview items and listview from the click event listener of done button that is inside custom adapter class.
public class TaskListFragment extends Fragment implements TaskListAdapter.RefreshAdapter{//change
private DatabaseHelper dbHelper;
private TextView taskTitle;
private ListView taskListView;
private ArrayAdapter adapter;
private ArrayList<Task> items;
private int optionFocusedItemIndex;
#Nullable
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
dbHelper = new DatabaseHelper(getActivity());
View view= inflater.inflate(R.layout.task_list, container, false);
taskTitle = (TextView)view.findViewById(R.id.task_textview);
taskListView = (ListView)view.findViewById(R.id.listViewTaskList);
int type = getArguments().getInt("type");
switch (type){
case R.integer.task_list_all:
items = dbHelper.getAllTasks();
adapter = new TaskListAdapter(getActivity(),items);
taskListView.setAdapter(adapter);
adapter.setRefreshAdapter(this);//change
taskTitle.setText("All tasks");
break;
}
taskListView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
#Override
public boolean onItemLongClick(AdapterView<?> parent, View view, int position, long id) {
int tagId = Integer.valueOf(view.getTag().toString());
optionFocusedItemIndex = position;
showOptionDialog(tagId);
return true;
}
});
return view;
}
public void showOptionDialog(final int id)
{
LayoutInflater layoutInflater = LayoutInflater.from(getActivity());
View view = layoutInflater.inflate(R.layout.row_option_dialog, null);
final AlertDialog alertDialog = new AlertDialog.Builder(getActivity()).create();
Button doneBtn = (Button)view.findViewById(R.id.btn_row_option_done);
doneBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.markAsDone(id);
refreshListView();
alertDialog.cancel();
Toast.makeText(getActivity().getBaseContext(),"Marked as done",Toast.LENGTH_SHORT).show();
}
});
Button editBtn = (Button)view.findViewById(R.id.btn_row_option_edit);
editBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
MainActivity activity = (MainActivity)getActivity();
activity.replaceEditTaskFragment(id);
alertDialog.cancel();
}
});
Button deleteBtn = (Button)view.findViewById(R.id.btn_row_option_delete);
deleteBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.deleteTask(id);
items.remove(optionFocusedItemIndex);
adapter.notifyDataSetChanged();
Toast.makeText(getActivity().getBaseContext(),"Task deleted",Toast.LENGTH_SHORT).show();
alertDialog.cancel();
}
});
Button cancelBtn = (Button)view.findViewById(R.id.btn_row_option_cancel);
cancelBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
alertDialog.cancel();
}
});
alertDialog.setView(view);
alertDialog.show();
}
public void refreshListView()
{
if(items!=null)
{
Task taskOld = items.get(optionFocusedItemIndex);
if(taskOld!=null)
{
taskOld.setDone(true);
items.set(optionFocusedItemIndex, taskOld);
adapter.notifyDataSetChanged();
}
}
}
//change
#Override
public void OnlickRefreshAdapter(){
//todo your code here
items = dbHelper.getAllTasks();
adapter = new TaskListAdapter(getActivity(),items);
taskListView.setAdapter(adapter);
}
}
adapter class
public class TaskListAdapter extends ArrayAdapter<Task> {
private final Context context;
private final ArrayList<Task> values;
private final DatabaseHelper dbHelper;
private RefreshAdapter refreshAdapter;
public TaskListAdapter(Context context,ArrayList<Task> values)
{
super(context,-1,values);
this.context = context;
this.values = values;
this.dbHelper = new DatabaseHelper(context.getApplicationContext());
}
public Interface RefreshAdapter{
public void OnlickRefreshAdapter();
}
public setRefreshAdapter(RefreshAdapter refresh){
refreshAdapter = refresh;
}
#Override
public View getView(final int position,View convertView,ViewGroup parent)
{
LayoutInflater inflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View rowView = inflater.inflate(R.layout.task_list_row,parent, false);
rowView.setTag(values.get(position).getId());
TextView rowDescription = (TextView)rowView.findViewById(R.id.task_row_description);
rowDescription.setText(values.get(position).getDescription());
ImageView rowStatusIcon = (ImageView)rowView.findViewById(R.id.task_row_status_icon);
Long currentDateMillSec= System.currentTimeMillis();
Long dateMillSec = CommonHelper.convertStrDateToMilSec(values.get(position).getDate());//(date==null)?0:date.getTime();
if(values.get(position).getDone()==Boolean.TRUE)
{
rowStatusIcon.setImageResource(R.drawable.done_icon);
}
else if(dateMillSec>0 && dateMillSec<currentDateMillSec)
{
rowStatusIcon.setImageResource(R.drawable.failed_icon);
}
else{
rowStatusIcon.setImageResource(R.drawable.todo_icon);
}
TextView dateTf = (TextView)rowView.findViewById(R.id.task_row_date);
dateTf.setText(values.get(position).getDate());
Button doneBtn = (Button)rowView.findViewById(R.id.task_row_done_btn);
doneBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.markAsDone(values.get(position).getId());
//How can I update the listview items here ?
}
});
return rowView;
}
}
I got the answer, actually it is too simple. What I need to do is just add this code inside the click listener of done button in the custom adapter.
This is the click listener of the doneBtn in custom adapter:
doneBtn.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
dbHelper.markAsDone(values.get(position).getId());
//How can I update the listview items here ?
if(values!=null)
{
Task oldTask = values.get(position);
oldTask.setDone(Boolean.TRUE);
values.set(position,oldTask);
notifyDataSetChanged();
}
}
});
First activity : gridview, whenever u click on gridview item dialogBox is opened which contains spinner. Now, I want to display Selected Gridview item and selected spinner values in Second Activity contains Listview. When u click on secondtime the values are replaced in listview but not added.
Can anyone plz help me...........
MainActivity...
public class MainActivity extends Activity implements OnClickListener {
SharedPreferences SharedPrefs;
String sp_selected;
Spinner sp;
String s1;
String partname;
String partname1;
Button Parts_history;
Imageadapter image_adapter;
private static final String[] paths = { "Select Your Choice", "Type1",
"Type2", "Type3", "Type4" };
private static final int position = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.partsrepair);
image_adapter = new Imageadapter(this);
SharedPrefs = getSharedPreferences("Preference", MODE_PRIVATE);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setAdapter(new Imageadapter(this));
Parts_history = (Button) findViewById(R.id.partshistory_button);
Parts_history.setOnClickListener((this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, View v,
int position, long id) {
SharedPreferences.Editor edit = SharedPrefs.edit();
// partname = parent.getItemAtPosition(position).toString();
partname1 = image_adapter.names[position].toString();
image_adapter.names[position].toString();
Toast.makeText(MainActivity.this, "you Selected:" + partname1,
Toast.LENGTH_SHORT).show();
// edit.putString("SelectPart", partname1);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.repairtype_spinner);
dialog.setCancelable(true);
Spinner sp = (Spinner) dialog.findViewById(R.id.spinner_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item,paths);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if (position > 0) {
sp_selected = parent.getItemAtPosition(position)
.toString();
}
}
#Override
public void onNothingSelected(AdapterView<?>arg0) {
// TODO Auto-generated method stub
}
});
Button btnOk = (Button)dialog.findViewById(R.id.Button_sms_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor edit = SharedPrefs.edit();
if ((sp_selected != null)
&& !sp_selected.equals("Select Your Choice")) { //
edit.putString("SelectType", sp_selected);
Toast.makeText(getApplicationContext(),
"You selected:" + sp_selected,
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),
"Thank You!", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this,
"plz Select your Choice",
Toast.LENGTH_SHORT).show();
}} });
dialog.show(); }});}
public void onClick(View v) {
switch (v.getId()) {
case R.id.partshistory_button:
Intent intent = new Intent(MainActivity.this, ListViewItems.class);
intent.putExtra("Part", partname1);
intent.putExtra("Type", sp_selected);
startActivity(intent);
finish();
}}}
listview.class
public class ListViewItems extends Activity {
ArrayList<String> part, type;
ListView list;
public ListViewItems() {
// TODO Auto-generated constructor stub
part = new ArrayList<String>();
type = new ArrayList<String>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_summary);
Intent i = getIntent();
part.add(i.getStringExtra("Part"));
type.add(i.getStringExtra("Type"));
list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.listview, type);
list.setAdapter(new CustomViewAdapter(ListViewItems.this));
adapter.notifyDataSetChanged();
}
public class CustomViewAdapter extends BaseAdapter {
Context context;
public CustomViewAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
private class ViewHolder {
TextView text_part;
TextView text_type;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Log.d("hao",""+position);
LayoutInflater minflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = minflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text_part = (TextView) convertView
.findViewById(R.id.textView1);
// Log.d("hao", ""+holder.text_desc);
holder.text_type = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.text_type.setText(type.get(position));
holder.text_part.setText(part.get(position));
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return part.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}}
Imageadapter.class
public class Imageadapter extends BaseAdapter {
private Context mContext;
private LayoutInflater mlayoutinflater;
public Imageadapter(Context c) {
mContext = c;
mlayoutinflater = LayoutInflater.from(c);
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
class ViewHolder {
ImageView imageView;
TextView textView;
}
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
ViewHolder childHolder;
if (convertView == null) {
// if it's not recycled, initialize some
convertView = mlayoutinflater.inflate(R.layout.partsnames, null);
childHolder = new ViewHolder();
childHolder.imageView = (ImageView) convertView
.findViewById(R.id.imageView1);
childHolder.textView = (TextView) convertView
.findViewById(R.id.textView1);
convertView.setTag(childHolder);
} else {
childHolder = (ViewHolder) convertView.getTag();
}
childHolder.imageView.setImageResource(mThumbIds[position]);
childHolder.textView.setText(names[position]);
return convertView;
}
public Integer[] mThumbIds = { R.drawable.ic_launcher, R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher,R.drawable.ic_launcher,
R.drawable.ic_launcher, R.drawable.ic_launcher, };
public String[] names = { "First", "Second", "Third", "Fourth",
"Fifth", "Sixth", "Seventh" };
}
It seems the values are not really being overwritten. Each time the second activity is loaded new part and type ArrayLists are being created. In these new lists only the latest part and type are added (in the onCreate Function) which have travelled with the intent.
If you want the list to keep adding the part and type selected by the user you can maintain the lists on the MainActivity. So upon selection of each item and type add it to the list on the MainActivity and then pass it to the ListViewItems activity.
This way the list will always have all the items selected by you.
I must admit I am not 100% sure if I understood your question correctly. But I have tried to answer with as much as I did.
EDIT:
MainActivity:
public class MainActivity extends ActionBarActivity {
ArrayList<String> list;
int clickCount = 0;
static TextView textViewHelloWorld;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
try {
list = new ArrayList<String>();
textViewHelloWorld = (TextView) findViewById(R.id.textViewHelloWorld);
Button buttonAddElements = (Button) findViewById(R.id.buttonAddElement);
buttonAddElements.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
clickCount = clickCount + 1;
textViewHelloWorld.setText("Click Count" + clickCount);
list.add("Click number " + clickCount);
}
});
Button buttonStartNewActivity = (Button) findViewById (R.id.buttonStartNewActivity);
buttonStartNewActivity.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Bundle bundle = new Bundle();
bundle.putStringArrayList("list", list);
startActivity(new Intent(MainActivity.this, Main2Activity.class).putExtras(bundle));
}
});
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main, container,
false);
return rootView;
}
}
}
Main2Activity: (ListView Activity):
public class Main2Activity extends ActionBarActivity {
ArrayList<String> list;
ListView listView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main2);
list = getIntent().getStringArrayListExtra("list");
listView = (ListView) findViewById(R.id.listViewList);
String []dsf = new String[list.size()];
list.toArray(dsf);
listView.setAdapter(new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, dsf));
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main2, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_main2,
container, false);
return rootView;
}
}
}
EDIT2:
MainActivity.Java
public class MainActivity extends Activity implements OnClickListener {
SharedPreferences SharedPrefs;
String sp_selected;
Spinner sp;
String s1;
String partname;
String partname1;
Button Parts_history;
private ArrayList<String> parts;
private ArrayList<String> types;
Imageadapter image_adapter;
private static final String[] paths = { "Select Your Choice", "Type1",
"Type2", "Type3", "Type4" };
private static final int position = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.partsrepair);
image_adapter = new Imageadapter(this);
parts = new ArrayList<String>();
types = new ArrayList<String>();
SharedPrefs = getSharedPreferences("Preference", MODE_PRIVATE);
GridView gridview = (GridView) findViewById(R.id.gridView1);
gridview.setAdapter(new Imageadapter(this));
Parts_history = (Button) findViewById(R.id.partshistory_button);
Parts_history.setOnClickListener((this));
gridview.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(final AdapterView<?> parent, View v,
int position, long id) {
SharedPreferences.Editor edit = SharedPrefs.edit();
// partname = parent.getItemAtPosition(position).toString();
partname1 = image_adapter.names[position].toString();
parts.add(partname1);
image_adapter.names[position].toString();
Toast.makeText(MainActivity.this, "you Selected:" + partname1,
Toast.LENGTH_SHORT).show();
// edit.putString("SelectPart", partname1);
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.repairtype_spinner);
dialog.setCancelable(true);
Spinner sp = (Spinner) dialog.findViewById(R.id.spinner_1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
MainActivity.this,
android.R.layout.simple_spinner_item,paths);
sp.setAdapter(adapter);
sp.setOnItemSelectedListener(new OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent,
View view, int position, long id) {
if (position > 0) {
sp_selected = parent.getItemAtPosition(position)
.toString();
types.add(sp_selected);
}
}
#Override
public void onNothingSelected(AdapterView<?>arg0) {
// TODO Auto-generated method stub
}
});
Button btnOk = (Button)dialog.findViewById(R.id.Button_sms_ok);
btnOk.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
SharedPreferences.Editor edit = SharedPrefs.edit();
if ((sp_selected != null)
&& !sp_selected.equals("Select Your Choice")) { //
edit.putString("SelectType", sp_selected);
Toast.makeText(getApplicationContext(),
"You selected:" + sp_selected,
Toast.LENGTH_SHORT).show();
Toast.makeText(getApplicationContext(),
"Thank You!", Toast.LENGTH_LONG).show();
dialog.dismiss();
} else {
Toast.makeText(MainActivity.this,
"plz Select your Choice",
Toast.LENGTH_SHORT).show();
}} });
dialog.show(); }});}
public void onClick(View v) {
switch (v.getId()) {
case R.id.partshistory_button:
Bundle bundle = new Bundle();
bundle.putStringArrayList("parts", parts);
bundle.putStringArrayList("type", types);
Intent intent = new Intent(MainActivity.this, ListViewItems.class);
intent.putExtra("Part", partname1);
intent.putExtra("Type", sp_selected);
intent.putExtra("bundle", bundle);
startActivity(intent);
finish();
}}}
ListView:
public class ListViewItems extends Activity {
ArrayList<String> part, type;
ListView list;
public ListViewItems() {
// TODO Auto-generated constructor stub
part = new ArrayList<String>();
type = new ArrayList<String>();
}
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.sms_summary);
Intent i = getIntent();
// part.add(i.getStringExtra("Part"));
// type.add(i.getStringExtra("Type"));
part = i.getExtras().getBundle("bundle").getStringArrayList("parts");
type = i.getExtras().getBundle("bundle").getStringArrayList("types");
list = (ListView) findViewById(R.id.listView1);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(
getBaseContext(), R.layout.listview, type);
list.setAdapter(new CustomViewAdapter(ListViewItems.this));
adapter.notifyDataSetChanged();
}
public class CustomViewAdapter extends BaseAdapter {
Context context;
public CustomViewAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context = context;
}
private class ViewHolder {
TextView text_part;
TextView text_type;
}
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder = null;
// Log.d("hao",""+position);
LayoutInflater minflater = (LayoutInflater) context
.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
if (convertView == null) {
convertView = minflater.inflate(R.layout.listview, null);
holder = new ViewHolder();
holder.text_part = (TextView) convertView
.findViewById(R.id.textView1);
// Log.d("hao", ""+holder.text_desc);
holder.text_type = (TextView) convertView
.findViewById(R.id.textView2);
convertView.setTag(holder);
}
else
holder = (ViewHolder) convertView.getTag();
holder.text_type.setText(type.get(position));
holder.text_part.setText(part.get(position));
return convertView;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return part.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
}}
below is my code which create listview programically how i wil change this to radiolistview in listview what wil i do to change my code to show radio list???????? i want to change my listview which i show inside alert dailog to radio check listview
ublic class MainActivity extends Activity implements OnClickListener, OnItemClickListener{
private Button btn_listviewdialog=null;
private String TitleName[]={"Sunil Gupta","Ram Chnadra"," Abhishek Tripathi","Amit
Verma","Sandeep Pal","Awadhesh Diwakar","Shishir Verma","Ravi Vimal","Prabhakr Singh","Manish
Srivastva","Jitendra Singh","Surendra Pal"};
private ArrayList<String> array_sort;
private AlertDialog myalertDialog=null;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
btn_listviewdialog=(Button)findViewById(R.id.button_listviewdialog);
btn_listviewdialog.setOnClickListener(this);
}
#Override
public void onClick(View arg0) {
AlertDialog.Builder myDialog = new AlertDialog.Builder(MainActivity.this);
final ListView listview=new ListView(MainActivity.this);
array_sort=new ArrayList<String> (Arrays.asList(TitleName));
LinearLayout layout = new LinearLayout(MainActivity.this);
layout.setOrientation(LinearLayout.VERTICAL);
layout.addView(listview);
myDialog.setView(layout);
CustomAlertAdapter arrayAdapter=new CustomAlertAdapter(MainActivity.this,
array_sort);
listview.setAdapter(arrayAdapter);
listview.setOnItemClickListener(this);
myDialog.setNegativeButton("cancel", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialog, int which) {
dialog.dismiss();
}
});
myalertDialog=myDialog.show();
}
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {
myalertDialog.dismiss();
String strName=TitleName[position];
// txt_item.setText(strName);
}
}
public class CustomAlertAdapter extends BaseAdapter{
Context ctx=null;
ArrayList<String> listarray=null;
private LayoutInflater mInflater=null;
public CustomAlertAdapter(Activity activty, ArrayList<String> list)
{
this.ctx=activty;
mInflater = activty.getLayoutInflater();
this.listarray=list;
}
#Override
public int getCount() {
return listarray.size();
}
#Override
public Object getItem(int arg0) {
return null;
}
#Override
public long getItemId(int arg0) {
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup arg2) {
final ViewHolder holder;
if (convertView == null ) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.alertlistrow, null);
holder.titlename = (TextView)
convertView.findViewById(R.id.textView_titllename);
convertView.setTag(holder);
}
else {
holder = (ViewHolder) convertView.getTag();
}
String datavalue=listarray.get(position);
if(position == getCount()-1){
holder.titlename.setTextColor(Color.GREEN);
}
holder.titlename.setText(datavalue);
return convertView;
}
private static class ViewHolder {
TextView titlename;
}
}
Did you tried this???
int to[] = new int[] { android.R.id.text1 };
String from[] = new String[] { values };
SimpleAdapter simpleAdapter;
simpleAdapter = new SimpleAdapter(getSherlockActivity(), ArrList,android.R.layout.simple_list_item_single_choice, from, to);
listView.setChoiceMode(AbsListView.CHOICE_MODE_SINGLE);
I want to select all check boxes in a listview but I'm not able to get checkbox objects from the listview. I can select a single check box but not multiple check boxes.
Your suggestion are appreciable.
Code:
public class MainActivity extends Activity {
#Override
public void onCreate(Bundle icicle) {
super.onCreate(savedInstanceState);
setContentView(R.layout.bir);
mainListView = (ListView) findViewById(R.id.mainListView);
selectall = (Button) findViewById(R.id.button1);
selectall.setOnClickListener(this);
save = (Button) findViewById(R.id.button2);
save.setOnClickListener(this);
mainListView.setOnItemClickListener(new AdapterView.OnItemClickListener()
{
#Override
public void onItemClick(AdapterView<?> parent, View item,
int position, long id) {
}
});
}
}
class Amphian:
private static class Amphian
{
private String name = "" ;
private boolean checked = false ;
public Amphian( String name )
{
this.name = name ;
}
public Amphian( String name, boolean checked )
{
this.name = name ;
this.checked = checked ;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public boolean isChecked() {
return checked;
}
public void setChecked(boolean checked) {
this.checked = checked;
}
#Override
public String toString() {
return name ;
}
public void toggleChecked()
{
checked = !checked ;
}
}
class AmphiansArrayAdapter:
public class AmphiansArrayAdapter extends ArrayAdapter<Amphian>
{
Integer name[] =
{
R.raw.ducks_landing_in_water,
R.raw.flicker_chicks_feeding,
R.raw.geese_honking_loud,
R.raw.geese_honking_distant,
R.raw.gold_finch,
R.raw.humming_bird_feeding,
R.raw.indigo_bunting,
R.raw.loons,
R.raw.little_blue_heron_fishing,
R.raw.pelican_chick,
R.raw.purple_martins,
R.raw.red_winged_blackbird,
R.raw.shorebirds_close,
R.raw.shorebirds_distant,
R.raw.shorebirds_misc,
R.raw.shoreseabirds,
R.raw.snow_geese_flock,
R.raw.terns,
R.raw.tufted_titmouse,
R.raw.tundra_swans,
R.raw.wood_stork_chicks,
R.raw.woodpecker_tapping
};
private final LayoutInflater inflater;
public AmphiansArrayAdapter(Context context, List<Amphian> amphianList)
{
super( context, R.layout.simplerow, R.id.rowTextView, amphianList );
inflater = LayoutInflater.from(context) ;
}
#Override
public View getView( final int position, View convertView , ViewGroup parent)
{
final Amphian amphian=this.getItem(position);
mp=new MediaPlayer();
if ( convertView == null )
{
convertView = inflater.inflate(R.layout.simplerow, null);
// Find the child views.
textView = (TextView) convertView.findViewById( R.id.rowTextView );
checkBox = (CheckBox) convertView.findViewById( R.id.checkBox1 );
button = (Button)convertView.findViewById(R.id.button1);
// Optimization: Tag the row with it's child views, so we don't have to
// call findViewById() later when we reuse the row.
convertView.setTag( new AmphianViewHolder(textView,checkBox,button) );
// If CheckBox is toggled, update the planet it is tagged with.
checkBox.setOnClickListener( new View.OnClickListener()
{
#Override
public void onClick(View v)
{
cb= (CheckBox) v;
Log.e("cb",String.valueOf(cb));
Amphian amphian = (Amphian) cb.getTag();
Log.e("cb",String.valueOf(cb.getTag()));
amphian.setChecked(cb.isChecked());
Log.e("dd", "ddd");
}
});
button.setOnClickListener(new OnClickListener()
{
#Override
public void onClick(View v)
{
Button bu=(Button)v;
Amphian amphian;
//= (Amphian) bu.getTag();
//Log.e(String.valueOf(amphian),"ddd");
Try this.
public class MainActivity extends Activity implements OnClickListener {
public class LVSample3Adapter extends BaseAdapter{
private Context context;
private List<LVSample3Item> itemList;
public LVSample3Adapter(List<LVSample3Item> lstItems,
MainActivity mainActivity) {
// TODO Auto-generated constructor stub
this.context=mainActivity;
this.itemList=lstItems;
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return itemList.size();
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return itemList.get(position);
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return 0;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.e("lstItems1:", String.valueOf(position));
LVSample3Item item = itemList.get(position);
convertView =LayoutInflater.from(context).inflate(R.layout.list, parent, false);
TextView t1=(TextView)convertView.findViewById(R.id.textView1);
t1.setText(item.getTitle());
CheckBox chb1=(CheckBox)convertView.findViewById(R.id.checkBox1);
chb1.setChecked(item.getstate());
return convertView;
}
}
/** Called when the activity is first created. */
private ListView lv;
private ListAdapter adapter;
private Button btn1,btn2;
private List<LVSample3Item> lstItems;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
btn1=(Button)findViewById(R.id.button1);
btn2=(Button)findViewById(R.id.button2);
btn1.setOnClickListener(this);
btn2.setOnClickListener(this);
lstItems = new ArrayList<LVSample3Item>();
LVSample3Item item = new LVSample3Item("drinks",false);
lstItems.add(item);
item = new LVSample3Item("chat",false);
lstItems.add(item);
item = new LVSample3Item("chat1",true);
lstItems.add(item);
item = new LVSample3Item("chat2",false);
lstItems.add(item);
adapter = new LVSample3Adapter(lstItems, this);
lv=(ListView)findViewById(R.id.listView1);
lv.setAdapter(adapter);
}
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(v.getId()==R.id.button1){
Log.e("lstItems:", String.valueOf(lstItems.size()));
for(int i=0;i<lstItems.size();i++){
LVSample3Item item=lstItems.get(i);
if(!item.getstate()){
item.setpath(true);
}
}
((BaseAdapter) adapter).notifyDataSetChanged();
}else if(v.getId()==R.id.button2){
for(int i=0;i<lstItems.size();i++){
LVSample3Item item=lstItems.get(i);
if(item.getstate()){
item.setpath(false);
}
}
((BaseAdapter) adapter).notifyDataSetChanged();
}
}
}
public class LVSample3Item implements Serializable {
private String title;
private boolean state;
public LVSample3Item(String title,boolean imagepath) {
this.title = title;
this.state=imagepath;
}
public String getTitle() {
return title;
}
public boolean getstate() {
return state;
}
public void setTitle(String title) {
this.title = title;
}
public void setpath(boolean imagepath) {
this.state = imagepath;
}
}
There is too much code to read, so I give you a sample how to do that:
int count = list.getCount();
for (int i = 0; i < count; i++) {
View child = list.getItemAtPosition(i);
//check that child..
}
or
int count = list.getChildCount();
for (int i = 0; i < count; i++) {
View child = list.getChildAt(i);
//check that child..
}
selectall.setOnClickListener(new onClickListener(){
#Override
public void onClick(View v) {
for (int i = 0; i < list.size(); i++) {
list.getItem(i).setChecked(true);
}
}
});
try doing soething like this