简体   繁体   中英

android list view items

I have a ListView , i made a custom_row for the items in the list , each row contains 2 TextView`s named (textView1 and textView2) and a ImageView, when i click on a item , a AlertDialog appears that has a input text there and OK , Cancel buttons. After entering something in the input of alertdialog and clicking ok i want to modify textView2 from the item in the ListView i clicked. How can i do that?

list.setOnItemClickListener(new AdapterView.OnItemClickListener() {

      public void onItemClick(AdapterView<?> arg0, View arg1, int position, long arg3) {

        TextView tv=new TextView(getApplicationContext());
        //Log.i("da","Clicked : "+labelData[position]);
        setLabel(labelData[position]);
        tv=(TextView)findViewById(R.id.textView2);
        tv.setText("das");


      }

 public void setLabel(String poz){

     AlertDialog.Builder alertDialog = new AlertDialog.Builder(this);
     alertDialog.setTitle("Set "+poz);
     alertDialog.setMessage("Enter "+poz);
     final EditText input = new EditText(this);
     alertDialog.setView(input);
     alertDialog.setPositiveButton("Ok", new DialogInterface.OnClickListener() {
         public void onClick(DialogInterface dialog, int whichButton) {
           String value = input.getText().toString();
           Log.i("da","Clicked : "+value);
           }
         });

     alertDialog.setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
           public void onClick(DialogInterface dialog, int whichButton) {
             // Canceled.
           }
         });

     alertDialog.show();
}

What you are looking for is fetching the result from the called activity. In summary, here are the methods to implement in the parent activity: 1. startActivtyForResult(...) 2. onActivityResult(...)

The child Activity should complete the work as usual and finally call: 1. setResult(...) 2. finish()

You can read more here: http://saigeethamn.blogspot.com/2009/08/android-developer-tutorial-for_31.html

On Click Ok You get String from Edittext(in Your Case input) And also Position .Now Just set String in your Array I mean Remove old String Which you Used in setText in Your textview2.And add this.Then adapter.notifyDatasetChanged();.You should use Dynamic array to remove or add String value from Alert .I mean...

        List<String> list = new ArrayList<String>();

        list.remove(position);
        list.set(position,YourAlertTextfiledValue);

        list.get(position);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM