我这个编辑框怎么获取不到输入的值
publicclassTestContentActivityextendsActivity{privateListViewlvtestList=null;privateE...
public class TestContentActivity extends Activity {
private ListView lvtestList = null;
private EditText etAnswer = null;
private Button btnAnswer = null;
private TextView tvAnswerResult =null;
int positionToDownload = -1;
private LinearLayout ll = null;
BaseAdapter ba = new BaseAdapter() {
/* (non-Javadoc)
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ll=(LinearLayout)getLayoutInflater().inflate(R.layout.test,null);
TextView tvTestTitle=(TextView)ll.findViewById(R.id.tvTestTitle);
int position1 = position+1;
tvTestTitle.setText("title");
TextView tvTestA=(TextView)ll.findViewById(R.id.tvTestA);
tvTestA.setText("A");
TextView tvTestB=(TextView)ll.findViewById(R.id.tvTestB);
tvTestB.setText("A");
TextView tvTestC=(TextView)ll.findViewById(R.id.tvTestC);
tvTestC.setText("A");
TextView tvTestD=(TextView)ll.findViewById(R.id.tvTestD);
tvTestD.setText("A");
etAnswer = (EditText)ll.findViewById(R.id.etAnswer);
tvAnswerResult = (TextView)ll.findViewById(R.id.tvAnswerResult);
btnAnswer = (Button)ll.findViewById(R.id.btnAnswer);
btnAnswer.setId(position);
btnAnswer.setOnClickListener(listenerToAnswerResult); //设置按钮
return ll;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public int getCount() {
return testList.size();
}
};
View.OnClickListener listenerToAnswerResult = new View.OnClickListener() {
@Override
public void onClick(final View v) {
positionToDownload = v.getId(); //获得ID
new AlertDialog.Builder(TestContentActivity.this)
.setTitle("提示")
.setIcon(R.drawable.alert_icon)
.setMessage("查看正确答案?")
.setPositiveButton(
"确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String answer = etAnswer.getText().toString();
Log.v("answer from user", answer);
}
})
.setNegativeButton(
"取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {}
}
).show();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_content);
lvtestList = (ListView)findViewById(R.id.lvtestList);
lvtestList.setAdapter(ba);
}
} 展开
private ListView lvtestList = null;
private EditText etAnswer = null;
private Button btnAnswer = null;
private TextView tvAnswerResult =null;
int positionToDownload = -1;
private LinearLayout ll = null;
BaseAdapter ba = new BaseAdapter() {
/* (non-Javadoc)
* @see android.widget.Adapter#getView(int, android.view.View, android.view.ViewGroup)
*/
@Override
public View getView(final int position, View convertView, ViewGroup parent) {
ll=(LinearLayout)getLayoutInflater().inflate(R.layout.test,null);
TextView tvTestTitle=(TextView)ll.findViewById(R.id.tvTestTitle);
int position1 = position+1;
tvTestTitle.setText("title");
TextView tvTestA=(TextView)ll.findViewById(R.id.tvTestA);
tvTestA.setText("A");
TextView tvTestB=(TextView)ll.findViewById(R.id.tvTestB);
tvTestB.setText("A");
TextView tvTestC=(TextView)ll.findViewById(R.id.tvTestC);
tvTestC.setText("A");
TextView tvTestD=(TextView)ll.findViewById(R.id.tvTestD);
tvTestD.setText("A");
etAnswer = (EditText)ll.findViewById(R.id.etAnswer);
tvAnswerResult = (TextView)ll.findViewById(R.id.tvAnswerResult);
btnAnswer = (Button)ll.findViewById(R.id.btnAnswer);
btnAnswer.setId(position);
btnAnswer.setOnClickListener(listenerToAnswerResult); //设置按钮
return ll;
}
@Override
public long getItemId(int position) {
return 0;
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public int getCount() {
return testList.size();
}
};
View.OnClickListener listenerToAnswerResult = new View.OnClickListener() {
@Override
public void onClick(final View v) {
positionToDownload = v.getId(); //获得ID
new AlertDialog.Builder(TestContentActivity.this)
.setTitle("提示")
.setIcon(R.drawable.alert_icon)
.setMessage("查看正确答案?")
.setPositiveButton(
"确定",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String answer = etAnswer.getText().toString();
Log.v("answer from user", answer);
}
})
.setNegativeButton(
"取消",
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog,
int which) {}
}
).show();
}
};
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.test_content);
lvtestList = (ListView)findViewById(R.id.lvtestList);
lvtestList.setAdapter(ba);
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询