我将类对象放在一个微调视图中,可以显示它们,但显示的是类似于: wxyg.dash1.object.abc.adb93931的完全限定的类名。在我的类中,我有以下属性: gridNickName、gridName、firstName、lastName、password和loginURI。是否有一些属性我可以设置,以便在微调器视图中显示的是这些属性之一?但是整个类对象仍然需要在列表中。我需要调整我的适配器吗?这就是我简要了解的内容。
//getting arrays from strings file
String[] regions;
Spinner gridSpinner;
Spinner regionSpinner;
ArrayList <Grid> al = new ArrayList<Grid>();
Grid Grid1 = new Grid("meet grid1", "GridHB5", "pqppq", "wdwd","wdwdww", "www.google.com");
Grid Grid2 = new Grid("meet grid2", "GridHB6", "zzz", "uuu", "secret1","www.ebay.com");
Grid Grid3 = new Grid("meet grid3", "GridHB7", "xxx", "dskd", "secret3","www.amazon.com");
Grid Grid4 = new Grid("meet grid4", "GridHB8", "qqq", "dsdsd", "secret4","www.me.com");
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView (R.layout.activity_f1);
setTitleFromActivityLabel (R.id.title_text);
//declaring variables
al.add(Grid1);
al.add(Grid2);
al.add(Grid3);
al.add(Grid4);
Button submitButton = (Button) findViewById(R.id.button1);
Button cancelButton = (Button) findViewById(R.id.button2);
//getting arrays from strings file
regions = getResources().getStringArray(R.array.regions_array);
// grids = getResources().getStringArray(R.array.grids_array);
this.gridSpinner = (Spinner) findViewById(R.id.gridSpinner);
this.regionSpinner = (Spinner) findViewById(R.id.regionSpinner);
//creating adapters for both spinners
final ArrayAdapter<Grid> dataAdapter = new ArrayAdapter<Grid>(this, android.R.layout.simple_spinner_item, al);
ArrayAdapter<String> regionAdapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, regions);
// drop down layout style with radio button type.
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
regionAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
// attaching data adapters to spinners
gridSpinner.setAdapter(dataAdapter);
regionSpinner.setAdapter(regionAdapter);一如既往,我真的很感谢你们帮我看这个。我相信这是一个很容易解决的问题,而且可能有一个我不知道的属性。
再次感谢!
发布于 2012-06-20 01:47:06
在网格类中定义您自己的toString()方法。
public String toString() {
return gridName; // or gridNickName + lastName; Whatever you want
}发布于 2012-06-20 01:51:26
您需要创建自定义适配器而不是ArrayAdapter,并实现自定义适配器的getView()并将textView设置为适当的值。您面临的问题是因为ArrayAdapter只是对列表中提供的对象使用了.toString函数,在本例中就是Grid对象
https://stackoverflow.com/questions/11106347
复制相似问题