我的截图和代码如下。应用程序崩溃当我输入所有信息并按保存详细信息按钮时!
有人可以帮忙解决吗?
还有一个问题:我稍后需要此对话框才能将其插入到每个列表视图中。这难吗?
当我写下我想要的所有信息并按保存详细信息时,应用程序崩溃了! 有人可以帮忙吗?
这也是我的代码:`
package com.example.user.dialogbox;
import android.app.Activity;
import android.app.Dialog;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.Window;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
public class MainActivity extends Activity{
Button btn_details;
TextView textDialog1;
TextView textDialog2;
TextView textDialog3;
TextView textDialog4;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
textDialog1 = (TextView)findViewById(R.id.text1 );
textDialog2 = (TextView)findViewById(R.id.text2);
textDialog3 = (TextView)findViewById(R.id.text3);
textDialog4 = (TextView)findViewById(R.id.text4);
btn_details = (Button)findViewById(R.id.button_details);
btn_details.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showCustomDialog(textDialog1);
showCustomDialog(textDialog2);
showCustomDialog(textDialog3);
showCustomDialog(textDialog4);
}
});
}
protected void showCustomDialog(final TextView _textDialog) {
final Dialog dialog = new Dialog(MainActivity.this);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.customdialog);
final EditText edit1 = (EditText)dialog.findViewById(R.id.edit1);
final EditText edit2 = (EditText)dialog.findViewById(R.id.edit2);
final EditText edit3 = (EditText)dialog.findViewById(R.id.edit3);
final EditText edit4 = (EditText)dialog.findViewById(R.id.edit4);
final TextView text1 = (TextView)dialog.findViewById(R.id.text1);
final TextView text2 = (TextView)dialog.findViewById(R.id.text2);
final TextView text3 = (TextView)dialog.findViewById(R.id.text3);
final TextView text4 = (TextView)dialog.findViewById(R.id.text4);
Button button = (Button)dialog.findViewById(R.id.button1);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
_textDialog.setText(edit1.getText().toString());
_textDialog.setText(edit2.getText().toString());
_textDialog.setText(edit3.getText().toString());
_textDialog.setText(edit4.getText().toString());
_textDialog.setText(text1.getText().toString());
_textDialog.setText(text2.getText().toString());
_textDialog.setText(text3.getText().toString());
_textDialog.setText(text4.getText().toString());
dialog.dismiss();
}
});
dialog.show();
}
}

答案 0 :(得分:0)
问题是你试图一次显示很多对话框,这不好尝试显示一个包含你想要显示的所有视图的对话框:)
将对话框中的值插入Listview并不困难您可以将值存储到临时列表中,如 ArrayList ,然后您可以填写列表视图:)
此链接可以帮助您: