简体   繁体   English

android列表查看项

[英]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. 我有一个ListView,我为列表中的项目创建了一个custom_row,每行包含2个TextView的名称(textView1和textView2)和一个ImageView,当我单击一个项目时,出现AlertDialog,那里有输入文本,确定,取消按钮。 After entering something in the input of alertdialog and clicking ok i want to modify textView2 from the item in the ListView i clicked. 在alertdialog的输入中输入某些内容并单击确定之后,我想从我单击的ListView中的项目中修改textView2。 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(...) 总之,以下是在父活动中实现的方法:1. startActivtyForResult(...)2. onActivityResult(...)

The child Activity should complete the work as usual and finally call: 1. setResult(...) 2. finish() 子Activity应该照常完成工作并最终调用:1. setResult(...)2. finish()

You can read more here: http://saigeethamn.blogspot.com/2009/08/android-developer-tutorial-for_31.html 您可以在此处了解更多信息: 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... 单击OK,您就可以从Edittext(在您的情况下输入)中获取String ,还可以Position 。现在只需在数组中设置String,我的意思是删除在textview2中的setText中使用的旧字符串,然后添加它。然后adapter.notifyDatasetChanged();您应该使用动态数组从Alert中删除或添加String值。我的意思是...

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

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

        list.get(position);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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