【发布时间】:2015-07-31 10:37:25
【问题描述】:
我的屏幕截图和代码如下。当我输入所有信息并按保存详细信息按钮时,应用程序崩溃!
谁能帮忙解决?
还有一个问题:稍后我需要这个对话框来将它插入到我的每个列表视图中。有那么难吗?
当我写下我想要的所有信息并按保存详细信息时,应用程序崩溃了! 有人可以帮忙吗?
这也是我的代码:`
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();
}
}
【问题讨论】:
-
为什么在按钮 click.well 上反复调用
showCustomDialog
方法,这不是一个好方法。您可能需要发布错误日志。