0

リストを作成しました。リスト項目をクリックすると、別の名前のリストであるJavaクラスを実行したいと思います。

これが私のコードです:

public class SecondAct extends ListActivity {
   private String[] items = { "Pending Retailers", "Ordered Retailers",
         "No Order Retailers", "Today's Plan", "Messages", "Daily Sales",
         "Pending Invoices", "Day Close", "Tools and Updates", "Exit" };

   /** Called when the activity is first created. */
   @Override
   public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);

      ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
            android.R.layout.simple_list_item_multiple_choice, items);
      // Get the activity's ListView and set its choice mode as multiple choice
      getListView().setChoiceMode(ListView.CHOICE_MODE_MULTIPLE);
      setListAdapter(adapter);
   }

   protected void onListItemClick(ListView l, View v, int position, long id) {
      // TODO Auto-generated method stub

      super.onListItemClick(l, v, position, id);
      String selectionValue = "";
      selectionValue = (String) getListView().getItemAtPosition(position);

      Log.i("List Selection Value: ",
            (String) getListView().getItemAtPosition(position));

      if (selectionValue.equalsIgnoreCase("Pending Retailers")) {

         Intent intent = new Intent("my.com.npi.List");
         startActivity(intent);
         AlertDialog alertDialog = new AlertDialog.Builder(SecondAct.this)
               .create();
         alertDialog.setTitle("Pending Retailers Selected");

         alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {

               // here we i add functions

            }
         });

         // alertDialog.setIcon(R.drawable.icon);
         alertDialog.show();
      }

      else if (selectionValue.equalsIgnoreCase("Exit")) {
         finish();
      }
   }
}

最初の項目をクリックすると、アプリケーションが強制的に閉じられます。インテントを使用して新しいアクティビティを開始しましたが、機能していません。どうしようもなく立ち往生!助けてください。

ありがとう。

4

2 に答える 2

1

独自のアプリケーションにアクティビティがある場合は、次を使用します。

Intent electIntent = new Intent();
electIntent.setClass(SecondAct.this, List.class);
startActivity(electIntent);

とAndroidManifestで

<activity
   android:name = ".List" />

このインテントを使用して、アプリケーションから別のアプリアクティビティを開始します。

Intent intent25 = new Intent(Intent.ACTION_MAIN).addCategory(
Intent.CATEGORY_LAUNCHER).setClassName("APP_PACKAGE_NAME",
"APP_PACKAGE_NAME.TestActivity").addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
.addFlags(Intent.FLAG_FROM_BACKGROUND).setComponent(new ComponentName("APP_PACKAGE_NAME",
"APP_PACKAGE_NAME.TestActivity"));
getApplicationContext().startActivity(intent25);
于 2012-05-11T10:35:54.103 に答える
1

マニフェストに新しいアクティビティを最初に登録する

マニフェストのアプリケーションタグの前に、次のようなパッケージを宣言します

<package name="my.com.npi">

<activity android:name = ".List" />

次に、Intentで正しい正しいクラス名を付けます。my.com.npiのように使用しないでください。これらのパッケージをインポートするだけで、プレーンな名前をList.classとして指定してください。

Intent intent = new Intent(this,List.class);
         startActivity(intent);
于 2012-05-11T12:03:35.497 に答える