0

専門家の皆さん。私はアンドロイドを初めて使用しています。次のアクティビティに進むインテントを生成しようとしています。リストビューを使用しています。リスト項目をクリックすると、クリックされた項目項目がそのクラスに移動するはずです。これが私のコードです。

package com.example.data_server_assi;

import android.app.ListActivity; import android.content.Intent; import android.os.Bundle; import android.view.View; import android.widget.ArrayAdapter; import android.widget.ListView; import android.widget.Toast;

public class Menu extends ListActivity{

String[] menu = {"AddInfo","DataBaseInfo"};

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setListAdapter(new ArrayAdapter<String>(Menu.this, android.R.layout.simple_list_item_1, menu));
}
@Override
protected void onListItemClick(ListView l, View v, int position, long id) {
    // TODO Auto-generated method stub
    super.onListItemClick(l, v, position, id);
    try {

        Toast.makeText(Menu.this, "Test" ,Toast.LENGTH_SHORT).show();
        Class menuItem = Class.forName("com.example.data_server_assi."+menu[position]);

        Intent menuIntent = new Intent(Menu.this,menuItem);

    } catch (ClassNotFoundException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

}`

4

2 に答える 2

1

コードの下に置くと、1 行のコードが抜けています。

Intent menuIntent = new Intent(Menu.this,menuItem);
 startActivity(menuIntent);

また

startActivity(new Intent(menu.this,menuItem));
于 2013-09-28T14:02:33.343 に答える