在我的应用程序中有两个编辑框,当单击适当的编辑框时,它将显示一个列表视图(这是另一个意图。从该用户必须选择 1 个输入,我将这些值分配给文本框。我的问题是当我将值设置为 1编辑框并单击另一个文本框以获取第一个文本框值不存在的值。
我的代码是:
带有编辑文本框的屏幕:
public void onCreate(Bundle savedInstanceState)
{
final String fromunit=getIntent().getStringExtra("Fromunit");
final String tounit=getIntent().getStringExtra("Tounit");
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
EditText medit=(EditText)findViewById(R.id.editText1);
EditText meditfrom=(EditText)findViewById(R.id.editText2);
Button b1=(Button)findViewById(R.id.button1);
EditText meditto=(EditText)findViewById(R.id.editText3);
meditfrom.setText(fromunit);
meditto.setText(tounit);
meditfrom.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1)
Intent FromIntent= new Intent(v.getContext(),Fromlist.class);
startActivity(FromIntent);
return false;
}
});
meditto.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent arg1)
{
// TODO Auto-generated method stub
Intent ToIntent= new Intent(v.getContext(),Tolist.class);
startActivity(ToIntent);
return false;
}
});
列表视图屏幕:
对于第一个编辑框:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.fromunit, FROMUNIT));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
// Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
// Toast.LENGTH_SHORT).show();
Intent prev=new Intent(view.getContext(),ServiceExampleActivity.class);
prev.putExtra("Fromunit",((TextView) view).getText());
startActivity(prev);
}
});
}
For 2nd edittextbox:
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(this, R.layout.fromunit, TOUNIT));
ListView lv = getListView();
lv.setTextFilterEnabled(true);
lv.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
// When clicked, show a toast with the TextView text
// Toast.makeText(getApplicationContext(), ((TextView) view).getText(),
// Toast.LENGTH_SHORT).show();
Intent prev=new Intent(view.getContext(),ServiceExampleActivity.class);
prev.putExtra("Tounit",((TextView) view).getText());
startActivity(prev);
}
});
}