为linkedhashmap中的项目分配一个整数值

时间:2018-09-30 10:36:24

标签: android android-activity integer parameter-passing linkedhashmap

我有一个活动FilmActivity.java

FilmActivity.java

  package com.blackevil.oneandonlythala;

 import android.content.Intent;
 import android.support.v7.app.AppCompatActivity;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.AdapterView;
 import android.widget.ListView;
 import android.widget.SimpleAdapter;

 import java.util.ArrayList;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.MobileAds;




public class FilmActivity extends AppCompatActivity {
private InterstitialAd interstitial;


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

    MobileAds.initialize(this, getString(R.string.admob_app_id));
    AdRequest adIRequest = new AdRequest.Builder().build();

    // Prepare the Interstitial Ad Activity
    interstitial = new InterstitialAd(FilmActivity.this);

    // Insert the Ad Unit ID
    interstitial.setAdUnitId(getString(R.string.admob_interstitial_id));

    // Interstitial Ad load Request
    interstitial.loadAd(adIRequest);

    // Prepare an Interstitial Ad Listener
    interstitial.setAdListener(new AdListener()
    {
        public void onAdLoaded()
        {
            // Call displayInterstitial() function when the Ad loads
            displayInterstitial();
        }
    });

    ListView resultsListView = findViewById(R.id.filmlist);


    LinkedHashMap<String, String> filmNames= new LinkedHashMap<>();
    filmNames.put("En veedu En Kanavar" , "1990");
    filmNames.put("Amaravathi","1993");
    filmNames.put("Prema Pusthakam","1993");
    filmNames.put("Paasamalargal","1994");
    filmNames.put("Pavithra","1994");
    filmNames.put("Rajavin Parvaiyile","1995");
    filmNames.put("Aasai","1995");
    filmNames.put("Vaanmathi","1996");
    filmNames.put("Kalloori Vaasal","1996");
    filmNames.put("Minor Mappillai","1996");
    filmNames.put("Kadhal Kottai","1996");
    filmNames.put("Nesam","1997");
    filmNames.put("Raasi","1997");
    filmNames.put("Ullaasam","1997");
    filmNames.put("Pagaivan","1997");
    filmNames.put("Rettai Jadai Vayasu","1997");
    filmNames.put("Kadhal Mannan","1998");
    filmNames.put("Aval Varuvala","1998");
    filmNames.put("Unnidathil Ennai Koduthen","1998");
    filmNames.put("Uyirodu Uyiraga","1998");
    filmNames.put("Thodarum","1999");
    filmNames.put("Unnai Thedi","1999");
    filmNames.put("Vaali","1999");
    filmNames.put("Anantha Poongatre","1999");
    filmNames.put("Amarkalam","1999");
    filmNames.put("Nee Varuvai Ena","1999");
    filmNames.put("Mugavari","2000");
    filmNames.put("Kandukondain Kandukondain","2000");
    filmNames.put("Unnai Kodu Ennai Tharuven","2000");
    filmNames.put("Dheena","2001");
    filmNames.put("Citizen","2001");
    filmNames.put("Poovellam Un Vasam","2001");
    filmNames.put("Aśoka","2001");
    filmNames.put("Red","2002");
    filmNames.put("Raja","2002");
    filmNames.put("Villain","2002");
    filmNames.put("Ennai Thalatta Varuvala","2003");
    filmNames.put("Anjaneya","2003");
    filmNames.put("Jana","2004");
    filmNames.put("Attagasam","2004");
    filmNames.put("Ji","2005");
    filmNames.put("Paramasivan","2006");
    filmNames.put("Thirupathi","2006");
    filmNames.put("Varalaru","2006");
    filmNames.put("Aalwar","2007");
    filmNames.put("Kireedam","2007");
    filmNames.put("Billa","2007");
    filmNames.put("Aegan","2008");
    filmNames.put("Aasal","2010");
    filmNames.put("Mankatha","2011");
    filmNames.put("Billa II","2012");
    filmNames.put("English Vinglish","2012");
    filmNames.put("Arrambam","2013");
    filmNames.put("Veeram","2014");
    filmNames.put("Yennai Arindhaal","2015");
    filmNames.put("Vedalam","2016");
    filmNames.put("Vivegam","2017");
    filmNames.put("Viswasam","2019");


    final List<LinkedHashMap<String, String>> listItems = new ArrayList<>();
    SimpleAdapter adapter = new SimpleAdapter(this, listItems, R.layout.biolist,
            new String[]{"First Line", "Second Line"},
            new int[]{R.id.text1, R.id.text2});


    Iterator it = filmNames.entrySet().iterator();
    while (it.hasNext()) {
        LinkedHashMap<String, String> resultsMap = new LinkedHashMap<>();
        Map.Entry pair = (Map.Entry) it.next();
        resultsMap.put("First Line", pair.getKey().toString());
        resultsMap.put("Second Line", pair.getValue().toString());
        listItems.add(resultsMap);
    }

    resultsListView.setAdapter(adapter);

    resultsListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position,
                                long id) {

            LinkedHashMap<String, String> selectItem = listItems.get(position);
            String firstLine = selectItem.get("First Line");
            String secondLine = selectItem.get("Second Line");

            Intent intent = new Intent(FilmActivity.this, FilmDetailActivity.class);

            intent.putExtra("firstLine", firstLine);
            intent.putExtra("secondLine", secondLine);
            startActivity(intent);
        }
    });

}
public void displayInterstitial()
{
    // If Interstitial Ads are loaded then show else show nothing.
    if (interstitial.isLoaded()) {
        interstitial.show();
    }
}

}

我需要将值1分配给第一项,将2分配给第二项,将3分配给第三项,依此类推,然后将其传递给下一个活动(FIlmDetailActivity.java)。在下一个活动中,如果该值是1,我将显示图像1,如果值是2,则显示图像2,依此类推。给我完整的代码,因为我是android开发的新手。

0 个答案:

没有答案