2017-06-20 66 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

相关问题