2017-06-20 52 views
-1

我一直在尋找很長時間,仍然沒有找到任何解決方案。 我想要的是,當你點擊這個自定義列表項目https://prnt.sc/flwqe3之一,當你點擊它時,每個列表項都有他自己的意圖。基於陣列列表項目中的位置的多種不同意圖

如果有人知道答案請讓我知道。

這是與自定義listItems中的activty

@Override 
    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout._main); 

     //Set the titel of the actionbar 
     TextView actionbartitel = (TextView) findViewById(R.id.actionbar_titel); 
     Typeface = Typeface.createFromAsset(getAssets(), "fonts/.ttf"); 
     actionbartitel.setTextSize(30); 
     actionbartitel.setTypeface(); 
     actionbartitel.setText(""); 

     //set the back button of the actionbar 
     ImageView actionbarimage = (ImageView) findViewById(R.id.actionbar_logo); 
     actionbarimage.setImageResource(R.drawable.ic_arrow_back_white_24dp); 
     // Set a click listener on that View 
     actionbarimage.setOnClickListener(new View.OnClickListener() { 
      // The code in this method will be executed when the family category is clicked on. 
      @Override 
      public void onClick(View view) { 
       // Create a new intent to open the {@link FamilyActivity} 
       Intent mainIntent = new Intent(Activity.this, MainActivity.class); 

       // Start the new activity 
       startActivity(mainIntent); 
      } 
     }); 


     interstitial = new InterstitialAd(this); 
     interstitial.setAdUnitId(getResources().getString(R.string.interstitial_ad_unit_id)); 
     AdRequest adRequest = new AdRequest.Builder().build(); 
     interstitial.loadAd(adRequest); 
     interstitial.setAdListener(new AdListener() { 
      public void onAdLoaded() { 
       displayInterstitial(); 
      } 
     }); 


     ListView listView = (ListView) findViewById(R.id.list); 
     ArrayList<Subjects> = new ArrayList<Subjects>(); 

     .add(new Subjects("", "", R.mipmap.ic_launcher, "5:60", 0xff00ffff, 
       Typeface.createFromAsset(getAssets(), "fonts/Font.ttf"), Typeface.createFromAsset(getAssets(), "fonts/timeFont.ttf"))); 

     .add(new Subjects("", " " + System.getProperty("line.separator") + " ", R.mipmap.ic_launcher, "5:60", 0xff0000ff, 
       Typeface.createFromAsset(getAssets(), "fonts/Font.ttf"), Typeface.createFromAsset(getAssets(), "fonts/timeFont.ttf"))); 


     WordAdapter adapter = new WordAdapter(this, list); 
     listView.setAdapter(adapter); 
    } 

    public void displayInterstitial() { 
     if (interstitial.isLoaded()) { 
      View loadingIndicator = findViewById(R.id.classicmprogressbar); 
      loadingIndicator.setVisibility(View.GONE); 

      interstitial.show(); 
     } 
    } 
} 

回答

2

至於你提到的數組列表中每個項目都有自己的意圖和ArrayList先後主題類對象,你可以做什麼,在Subject類,你可以添加一個Class對象像Class cls; 並把它添加到arrayList從而:

ArrayList<Subjects> subjects = new ArrayList<Subjects>();

.add(new Subjects("", "", R.mipmap.ic_launcher, "5:60", 0xff00ffff, 
      Typeface.createFromAsset(getAssets(), "fonts/Font.ttf"), Typeface.createFromAsset(getAssets(), "fonts/timeFont.ttf"),IntentOne.class)); 

    .add(new Subjects("", " " + System.getProperty("line.separator") + " ", R.mipmap.ic_launcher, "5:60", 0xff0000ff, 
      Typeface.createFromAsset(getAssets(), "fonts/Font.ttf"), Typeface.createFromAsset(getAssets(), "fonts/timeFont.ttf"),IntenTwo.class)); 

和列表項單擊您可以下面的代碼訪問使用

// Create a new intent to open the {@link FamilyActivity} 
      Intent mainIntent = new Intent(Activity.this, adapter.getItem(position).cls); 

      // Start the new activity 
      startActivity(mainIntent); 
+0

我編輯的主體,並添加類的列表項 – anomynous

+0

最終WordAdapter適配器=新WordAdapter(這一點,obsclassiclist); listView.setAdapter(adapter); listView.setOnItemClickListener(新ListView.OnItemClickListener(){ @覆蓋 公共無效onItemClick(適配器視圖父,觀景,INT位置,長的id){ //創建一個新的意圖打開{@link FamilyActivity} 意向mainIntent =新意圖(ObsclassicActivity.this,adapter.getItem(位置).CLS); //啓動新活動 startActivity(mainIntent);} 時 – anomynous

+0

點擊我仍然沒有happends有不正確的東西我的聽衆 – anomynous

相關問題