Java 对话框内容不会根据该行更改

Java 对话框内容不会根据该行更改,java,android,dialog,Java,Android,Dialog,我给所有行中的一个按钮,如果我们单击该按钮对话框必须出现在该行中,它必须根据该行显示内容 public void bindView(View view, Context context, final Cursor cursor){ int row_id = cursor.getColumnIndex("_id"); //Your row id (might need to replace) TextView tv = (TextV

我给所有行中的一个按钮,如果我们单击该按钮对话框必须出现在该行中,它必须根据该行显示内容

public void bindView(View view, Context context, final Cursor cursor){
                int row_id = cursor.getColumnIndex("_id");  //Your row id (might need to replace)
                TextView tv = (TextView) view.findViewById(R.id.text2);
                final TextView tv1 = (TextView) view.findViewById(R.id.text1);
                TextView tv2 = (TextView) view.findViewById(R.id.date);
                CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox);
                int col1 = cursor.getColumnIndex("expname");
                final String expname = cursor.getString(col1 );
                int col2 = cursor.getColumnIndex("expcontent");
                final String expcontent = cursor.getString(col2 );
                int col3 = cursor.getColumnIndex("expdate");
                final String expdate = cursor.getString(col3);
                cb.setTag(cursor.getPosition());
                cb.setChecked(mCheckStates.get(cursor.getPosition(), false));
                cb.setOnCheckedChangeListener(this);
              //  TextView tv2 = (TextView) view.findViewById(R.id.text3);
                //cursor.getColumnName(1)
                tv.setText( expname);
                tv1.setText( expcontent);
               tv2.setText(expdate);
                //tv2.setText( ""+cursor.getColumnIndex(GinfyDbAdapter.CATEGORY_COLUMN_COUNT));
             //   String[] from = new String[]{GinfyDbAdapter.CATEGORY_COLUMN_TITLE, GinfyDbAdapter.CATEGORY_COLUMN_CONTENT, GinfyDbAdapter.CATEGORY_COLUMN_COUNT}
                ImageButton button = (ImageButton) view.findViewById(R.id.sms);
                button.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        StringBuffer sb2 = new StringBuffer();
                    sb2.append("Title:");
                        sb2.append(Html.fromHtml(expname));
                        sb2.append(",Content:");
                        sb2.append(Html.fromHtml(expcontent));
                        sb2.append("\n");
                        String strContactList1 = (sb2.toString().trim());
                        sendsmsdata(strContactList1);
                    }
                });

                ImageButton button1 = (ImageButton) view.findViewById(R.id.mail);
                button1.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        StringBuffer sb3 = new StringBuffer();
                    sb3.append("Title:");
                        sb3.append(Html.fromHtml(expname));
                        sb3.append(",Content:");
                        sb3.append(Html.fromHtml(expcontent));
                        sb3.append("\n");
                        String strContactList2 = (sb3.toString().trim());
                        sendmaildata(strContactList2);
                    }
                });

                ImageButton button2 = (ImageButton) view.findViewById(R.id.btnaudioprayer);
                button2.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        //ADD STUFF HERE you know which row is clicked. and which button
                        typed = expcontent;
                        speakOut();
                    }
                });


                ImageButton button3 = (ImageButton) view.findViewById(R.id.bBlame);
                button3.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        //ADD STUFF HERE you know which row is clicked. and which button
                        dialog.show();

                    }
                });

                dialog=new Dialog(ExperiencesActivity.this);
                dialog.setContentView(R.layout.exp1);
                dialog.setCancelable(true);
                dialog.setTitle("My Experiences");

                textview1 = (TextView)dialog.findViewById(R.id.tv11);



                textview1.setText("Title:" + expname);
                textview2 = (TextView)dialog.findViewById(R.id.tv22);
                textview2.setText("Content:" + expcontent);
                Button button23=(Button)dialog.findViewById(R.id.btnSubmit);
                button23.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();

                    }
                });

但这里我的问题是,它不会在对话框中显示相应的内容,每当我们单击按钮中的第一个项目时,它都会显示按钮单击的所有行中的内容。对话框内容必须根据行进行更改。

您需要为文本视图创建saperate类。像

public void bindView(View view, Context context, final Cursor cursor){
                int row_id = cursor.getColumnIndex("_id");  //Your row id (might need to replace)
                TextView tv = (TextView) view.findViewById(R.id.text2);
                final TextView tv1 = (TextView) view.findViewById(R.id.text1);
                TextView tv2 = (TextView) view.findViewById(R.id.date);
                CheckBox cb = (CheckBox) view.findViewById(R.id.checkbox);
                int col1 = cursor.getColumnIndex("expname");
                final String expname = cursor.getString(col1 );
                int col2 = cursor.getColumnIndex("expcontent");
                final String expcontent = cursor.getString(col2 );
                int col3 = cursor.getColumnIndex("expdate");
                final String expdate = cursor.getString(col3);
                cb.setTag(cursor.getPosition());
                cb.setChecked(mCheckStates.get(cursor.getPosition(), false));
                cb.setOnCheckedChangeListener(this);
              //  TextView tv2 = (TextView) view.findViewById(R.id.text3);
                //cursor.getColumnName(1)
                tv.setText( expname);
                tv1.setText( expcontent);
               tv2.setText(expdate);
                //tv2.setText( ""+cursor.getColumnIndex(GinfyDbAdapter.CATEGORY_COLUMN_COUNT));
             //   String[] from = new String[]{GinfyDbAdapter.CATEGORY_COLUMN_TITLE, GinfyDbAdapter.CATEGORY_COLUMN_CONTENT, GinfyDbAdapter.CATEGORY_COLUMN_COUNT}
                ImageButton button = (ImageButton) view.findViewById(R.id.sms);
                button.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        StringBuffer sb2 = new StringBuffer();
                    sb2.append("Title:");
                        sb2.append(Html.fromHtml(expname));
                        sb2.append(",Content:");
                        sb2.append(Html.fromHtml(expcontent));
                        sb2.append("\n");
                        String strContactList1 = (sb2.toString().trim());
                        sendsmsdata(strContactList1);
                    }
                });

                ImageButton button1 = (ImageButton) view.findViewById(R.id.mail);
                button1.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        StringBuffer sb3 = new StringBuffer();
                    sb3.append("Title:");
                        sb3.append(Html.fromHtml(expname));
                        sb3.append(",Content:");
                        sb3.append(Html.fromHtml(expcontent));
                        sb3.append("\n");
                        String strContactList2 = (sb3.toString().trim());
                        sendmaildata(strContactList2);
                    }
                });

                ImageButton button2 = (ImageButton) view.findViewById(R.id.btnaudioprayer);
                button2.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        //ADD STUFF HERE you know which row is clicked. and which button
                        typed = expcontent;
                        speakOut();
                    }
                });


                ImageButton button3 = (ImageButton) view.findViewById(R.id.bBlame);
                button3.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        //ADD STUFF HERE you know which row is clicked. and which button
                        dialog.show();

                    }
                });

                dialog=new Dialog(ExperiencesActivity.this);
                dialog.setContentView(R.layout.exp1);
                dialog.setCancelable(true);
                dialog.setTitle("My Experiences");

                textview1 = (TextView)dialog.findViewById(R.id.tv11);



                textview1.setText("Title:" + expname);
                textview2 = (TextView)dialog.findViewById(R.id.tv22);
                textview2.setText("Content:" + expcontent);
                Button button23=(Button)dialog.findViewById(R.id.btnSubmit);
                button23.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();

                    }
                });
   private class ViewHolder {
            TextView textview1;
            TextView textview2;
             Button button23;
        }
更新您的对话框,如

public void showMyDialog(){

dialog=new Dialog(ExperiencesActivity.this);
ViewHolder viewholder;
                dialog.setContentView(R.layout.exp1);
                dialog.setCancelable(true);
                dialog.setTitle("My Experiences");

                ViewHolder.textview1 = (TextView)dialog.findViewById(R.id.tv11);
                ViewHolder.textview1.setText("Title:" + expname);
                ViewHolder.textview2 = (TextView)dialog.findViewById(R.id.tv22);
                ViewHolder.textview2.setText("Content:" + expcontent);
                ViewHolder.button23=(Button)dialog.findViewById(R.id.btnSubmit);
               ViewHolder.button23.setOnClickListener(new OnClickListener() {
                    @Override
                    public void onClick(View v) {

                        dialog.dismiss();

                    }
                });
 dialog.show();
}
并在单击按钮时调用showMyDialog()方法

 ImageButton button3 = (ImageButton) view.findViewById(R.id.bBlame);
                button3.setOnClickListener(new OnClickListener(){
                    @Override
                    public void onClick(View v){
                        //ADD STUFF HERE you know which row is clicked. and which button
                        showMyDialog();

                    }
                });

问题在于分配变量。@Hardy在这种情况下该怎么办,伙计,它的内容不同,而不是各自的one@Hardy现在代码运行良好,伙计,如果我们使用viewholder,它运行良好,你能告诉我为什么我必须在哪里写viewholder类吗?你能告诉我为什么如果我们使用viewholder,它工作得很好。。很高兴听到它起作用了。很高兴帮助你,伙计。这是因为它会为列表创建单独的对象。