我正在使用 aViewSwitcher
在两个视图之间切换(因为它应该被使用)。
这是ViewSwitcher
代码:
final ViewSwitcher viewSwitcher = new ViewSwitcher(getApplicationContext());
TextView t = new TextView(this);
[...]
t.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
viewSwitcher.showNext();
}
});
viewSwitcher.addView(t,
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT, 1f));
final String key = (String)map.keySet().toArray()[n];
if(key.contains("EditText"))
{
EditText e = new EditText(this);
[...]
e.setOnLongClickListener(new View.OnLongClickListener() {
@Override
public boolean onLongClick(View view) {
viewSwitcher.showPrevious();
return true;
}
});
viewSwitcher.addView(e,
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT, 1f));
}
else if (key.contains("Spinner"))
{
Spinner spin = new Spinner(getApplicationContext());
[...]
spin.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int i, long l) {
if(adapterView.getSelectedItemPosition() == 0)
viewSwitcher.showPrevious();
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
viewSwitcher.addView(spin,
new TableRow.LayoutParams(
TableRow.LayoutParams.MATCH_PARENT,
TableRow.LayoutParams.MATCH_PARENT, 1f));
}
事实是我试图将 ViewSwitcher 放在 List 中以便稍后获取值。
(就像以前我只使用 EditText 时一样),但它并没有真正起作用,因为我无法获得ViewSwitcher
.
所以这是我的问题:您知道如何获取当前在 ViewSwitcher 中选择的视图的值,以便我可以将其添加到列表中以供以后使用吗?
先感谢您。