0

我将类对象放在微调器视图中并可以显示它们,但显示的是完整的限定类名称,例如:wxyg.dash1.object.abc.adb93931。在我的课堂上,我有以下属性;gridNickName、gridName、firstName、lastName、密码和 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);

一如既往,我真的很感谢你们为我看这个。我确信这是一个简单的解决方法,并且可能有一个我不知道的属性。

再次感谢!

4

2 回答 2

2

在 Grid 类中定义自己的 toString() 方法。

public String toString() {
    return gridName; // or gridNickName + lastName; Whatever you want
}
于 2012-06-19T17:47:05.880 回答
0

您需要创建一个自定义适配器而不是 ArrayAdapter 并实现getView()自定义适配器并将 textView 设置为适当的值。您面临的问题是因为 ArrayAdapter 只是对列表中提供的对象使用 .toString 函数,在您的情况下是Grid对象

于 2012-06-19T17:51:26.270 回答