0

我有一个问题,我寻求了一点,但我不明白为什么它是附加的......

如果有人可以帮助我。

public class Menu extends Activity
{
private SQLiteDatabase db;

private GridView grid;
private Button add;
private Button info;
private Button deco;

private String lab[];
private String id[];

protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.menu);

    grid = (GridView) findViewById(R.id.grid);
    add = (Button) findViewById(R.id.add_account);
    info = (Button) findViewById(R.id.info);
    deco = (Button) findViewById(R.id.deconnexion);

    add.setOnClickListener(add_listener);
    info.setOnClickListener(info_listener);
    deco.setOnClickListener(deco_listener);

    try
    {
        db = openOrCreateDatabase("TMP_TTTT_TLA", MODE_PRIVATE, null);
    }
    catch(SQLiteException e)
    {
        Toast.makeText(Menu.this, "Impossible d'avoir accès à la base de donnéee.", Toast.LENGTH_LONG).show();
    }

    Cursor c = db.rawQuery("SELECT a_id, a_name FROM Account", null);

    lab = new String[c.getCount()];
    id = new String[c.getCount()];
    int i = 0;

    if (c.getCount() != 0 )
    {
        if  (c.moveToFirst())
        {
            do
            {
                lab[i] = c.getString(c.getColumnIndex("a_name"));
                id[i] = c.getString(c.getColumnIndex("a_id"));
                i++;
            }
            while(c.moveToNext());
        }
    }

    c.close();

    grid.setAdapter(new Adapter_Menu(this, lab));
    grid.setOnItemClickListener(new OnItemClickListener()
    {
        public void onItemClick(AdapterView parent, View v, int position, long id)
        {
            Intent x = new Intent(Menu.this, Account_View.class);
            x.putExtra("Id", id[position]);
            startActivity(x);
        }
    });
}
}

问题来自这一行:

x.putExtra("Id", id[position]);

据说表达式的类型必须是数组类型,但它解析为长。

请帮帮我。

4

1 回答 1

4

问题是您有两个名为 id 的变量:

private String id[];

long id

onItemClick

只需将您的更改onItemClickListener为以下内容:

public void onItemClick(AdapterView parent, View v, int position, long anid) 
    {
        Intent x = new Intent(Menu.this, Account_View.class);
        x.putExtra("Id", id[position]);
        startActivity(x);
    }

请注意您的最后一个参数的名称onItemClick

于 2013-07-31T17:17:17.457 回答