【问题标题】:android list view itemsandroid列表查看项目
【发布时间】:2012-02-23 14:56:49
【问题描述】:

我有一个 ListView,我为列表中的项目创建了一个 custom_row,每行包含 2 个名为(textView1 和 textView2)的 TextView 和一个 ImageView,当我单击一个项目时,会出现一个带有输入的 AlertDialog文本和 OK , Cancel 按钮。 在 alertdialog 的输入中输入内容并单击确定后,我想从单击的 ListView 中的项目中修改 textView2。 我该怎么做?

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();
}

【问题讨论】:

    标签: android listview


    【解决方案1】:

    单击确定后,您会从 Edittext 中获得 String(在您的案例输入中)以及 Position。现在只需在您的数组中设置字符串,我的意思是删除您在 textview2 中的 setText 中使用的旧字符串。然后添加。然后 adapter.notifyDatasetChanged();.You 应该使用动态数组从警报中删除或添加字符串值。我的意思是......

            List<String> list = new ArrayList<String>();
    
            list.remove(position);
            list.set(position,YourAlertTextfiledValue);
    
            list.get(position);
    

    【讨论】:

      【解决方案2】:

      您正在寻找的是从被调用的活动中获取结果。 总之,以下是在父活动中实现的方法: 1. startActivtyForResult(...) 2. onActivityResult(...)

      子Activity应该像往常一样完成工作,最后调用: 1. 设置结果(...) 2.finish()

      您可以在此处阅读更多内容: http://saigeethamn.blogspot.com/2009/08/android-developer-tutorial-for_31.html

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-12-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2023-04-02
        相关资源
        最近更新 更多