当我正在努力获取自定义微调器并在 toast 中显示值时。这些值正确设置为微调器,但我无法在吐司中显示它们。我的代码是
主.java
public class Main extends Activity {
ArrayList<String> ast = new ArrayList<String>();
Spinner customspinner;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
customspinner = (Spinner)findViewById(R.id.spinner1);
ast.add("111111");
ast.add("222222");
ast.add("333333");
ast.add("444444");
MyAdapter adp = new MyAdapter();
customspinner.setAdapter(adp);
System.out.println(ast);
customspinner.setOnItemSelectedListener(new OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapter, View v,
int position, long val) {
// TODO Auto-generated method stub
//here when spinner was selected I need to save those two custom textviews in two string and need to display them in toast....
//String getspineer = customspinner.getSelectedItem().toString();
//Toast.makeText(getApplicationContext(), "spinner --- " + getspineer , Toast.LENGTH_SHORT).show();
}
@Override
public void onNothingSelected(AdapterView<?> arg0) {
// TODO Auto-generated method stub
}
});
}
public class MyAdapter extends BaseAdapter{
@Override
public int getCount() {
// TODO Auto-generated method stub
return ast.size();
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View v = null;
LayoutInflater inflater = getLayoutInflater();
v = inflater.inflate(R.layout.customspinner, null);
TextView tv = (TextView)v.findViewById(R.id.textView1);
TextView tv1 = (TextView)v.findViewById(R.id.textView2);
String arlstdate[] = ast.get(position).split("~");
for (int i = 0; i < arlstdate.length; i++) {
tv.setText(arlstdate[i]);
tv1.setText(arlstdate[i]);
}
return v;
}
}
}
我在这里寻找的是,当我选择微调器时,我需要将以下两个 textview 值保存在两个字符串中,并且需要分别在 Toast 混乱中显示它们。
谁能帮我这个。经过大量搜索后,我找到了此代码,但无法保存到字符串和显示中的文本值..