I tried to solve it and got one solution pls go through the code below: listview. Java public class listview extends Activity implements OnItemClickListener{ ListView list; ListAdapter adapter; ArrayList nameArray; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.
OnCreate(savedInstanceState); setContentView(R.layout. Main);//xml should have an ListView element nameArray = new ArrayList(); nameArray. Add("Item1"); nameArray.
Add("Item2"); nameArray. Add("Item3"); nameArray. Add("Item4"); nameArray.
Add("Item5"); list = (ListView) findViewById(R.id. ListView); list. SetOnItemClickListener(listview.
This); adapter=new ListAdapter(listview. This, nameArray); list. SetAdapter(adapter); } @Override public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { showDialog(arg2); } @Override protected Dialog onCreateDialog(final int id) { Builder builder = new AlertDialog.
Builder(this); builder. SetMessage("Delete Event") . SetCancelable(true) .
SetPositiveButton("Ok, Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { nameArray. Remove(id); adapter=new ListAdapter(listview. This, nameArray); list.
SetAdapter(adapter); } }) . SetNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog dialog = builder.create(); dialog.show(); return super. OnCreateDialog(id); } } Adapter Class ListAdapter.
Java public class ListAdapter extends BaseAdapter { private Activity activity; private ArrayList name; private static LayoutInflater inflater=null; public ListAdapter(Activity a, ArrayList nameArray) { activity = a; name = nameArray; inflater = (LayoutInflater)activity. GetSystemService(Context. LAYOUT_INFLATER_SERVICE); } public int getCount() { return name.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public static class ViewHolder{ public TextView text; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; ViewHolder holder; if(convertView==null){ vi = inflater.
Inflate(R.layout. List_item, null); holder=new ViewHolder(); holder. Text=(TextView)vi.
FindViewById(R.id. Title); vi. SetTag(holder); } else holder=(ViewHolder)vi.getTag(); holder.text.
SetText(name. Get(position)); return vi; } }.
I tried to solve it and got one solution pls go through the code below: listview. Java public class listview extends Activity implements OnItemClickListener{ ListView list; ListAdapter adapter; ArrayList nameArray; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.
OnCreate(savedInstanceState); setContentView(R.layout. Main);//xml should have an ListView element nameArray = new ArrayList(); nameArray. Add("Item1"); nameArray.
Add("Item2"); nameArray. Add("Item3"); nameArray. Add("Item4"); nameArray.
Add("Item5"); list = (ListView) findViewById(R.id. ListView); list. SetOnItemClickListener(listview.
This); adapter=new ListAdapter(listview. This, nameArray); list. SetAdapter(adapter); } @Override public void onItemClick(AdapterView arg0, View arg1, int arg2, long arg3) { showDialog(arg2); } @Override protected Dialog onCreateDialog(final int id) { Builder builder = new AlertDialog.
Builder(this); builder. SetMessage("Delete Event") . SetCancelable(true) .
SetPositiveButton("Ok, Delete", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { nameArray. Remove(id); adapter=new ListAdapter(listview. This, nameArray); list.
SetAdapter(adapter); } }) . SetNegativeButton("No", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); AlertDialog dialog = builder.create(); dialog.show(); return super. OnCreateDialog(id); } } //Adapter Class ListAdapter.
Java public class ListAdapter extends BaseAdapter { private Activity activity; private ArrayList name; private static LayoutInflater inflater=null; public ListAdapter(Activity a, ArrayList nameArray) { activity = a; name = nameArray; inflater = (LayoutInflater)activity. GetSystemService(Context. LAYOUT_INFLATER_SERVICE); } public int getCount() { return name.size(); } public Object getItem(int position) { return position; } public long getItemId(int position) { return position; } public static class ViewHolder{ public TextView text; } public View getView(int position, View convertView, ViewGroup parent) { View vi=convertView; ViewHolder holder; if(convertView==null){ vi = inflater.
Inflate(R.layout. List_item, null); holder=new ViewHolder(); holder. Text=(TextView)vi.
FindViewById(R.id. Title); vi. SetTag(holder); } else holder=(ViewHolder)vi.getTag(); holder.text.
SetText(name. Get(position)); return vi; } }.
NotifyDataChanged is still better than recreating a new adapter, I think ;-) – Profete162 Oct 3 at 12:52 Surely It will be. I just gave one way of solving the issue... – Basil Oct 4 at 4:24.
I don't know what kind of data you are using. I imagine Cursor, database or List, feel free to tell us, so it will be easier to help. This example is for a list: protected void onListItemClick(View v, int pos, long id) { Log.
I(TAG, "onListItemClick id=" + id); //Display your Dialog (...) builder. SetPositiveButton("Ok, Delete", new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int id) { myList. Remove(pos); myAdapter.
NotifyDataChanged(); } }); }.
I'm using onItemClickListener that been implemented through Activity – PattabiRaman Oct 3 at 9:53 yes, but you need to add these 2 lines: myList. Remove(pos); myAdapter. NotifyDataChanged(); – Profete162 Oct 3 at 10:15.
You propably have some kind of Adapter, that you have feed with some kind of data. Remove the item from that list, and notifyDataChanged to the ListView. And finally: dialog.dismiss().
ItemLayout. SetOnClickListener(new OnClickListener() { @Override public void onClick(View arg0) { indexClick = position; } } if ((indexClick) == (position)) { itemLayout. SetBackgroundResource(R.drawable.
Tab_select); } otherwise put tab_unselected image.
List = (ListView) findViewById(R.id. Public void onItemClick(AdapterView Inflater = (LayoutInflater)activity.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.