简体   繁体   English

单击列表视图项后的图像滑块

[英]Image slider after listview item click

I have some 50-60 images. 我有一些50-60张图片。 I want to display a list of the title of those images and if i click a item the image corresponding to that item and details of that image have to be opened and then the next images should be viewed by sliding. 我想显示这些图像的标题列表,如果单击某个项目,则必须打开与该项目相对应的图像以及该图像的详细信息,然后应通过滑动查看下一个图像。 I have the code to display the listview and i need the code to onclick listener and image slider as i am a newbie in android development. 我有显示列表视图的代码,我需要代码来onclick侦听器和图像滑块,因为我是android开发中的新手。 the codes i have are 我的密码是

FilmActivity.java , activity_film.xml , filmlist.xml FilmActivity.java,activity_film.xml,filmlist.xml

These will display the listview using linked hashmap. 这些将使用链接的哈希图显示listview。 Now i need the rest of the code. 现在我需要其余的代码。

FilmActivity.java FilmActivity.java

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
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;

public class FilmActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_film);
    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");
    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);

}
} 

activity_film.xml activity_film.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">

<ListView
    android:id="@+id/filmlist"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentStart="true"
    android:layout_alignParentBottom="true"
    android:layout_marginBottom="0dp" />
</RelativeLayout>

filmlist.xml filmlist.xml

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark">

<TextView android:id="@+id/text1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textColor="@color/colorAccent"
    android:textSize="21sp"
    android:textStyle="bold"
    />

<TextView android:id="@+id/text2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="16sp"
    android:textColor="@color/white"
    android:textStyle="bold"
    />

</LinearLayout>

Setclicklistener your items after you can use a github library for a image slider. 可以将github库用于图像滑块后,请setclicklistener项目。 There are many libraries where you can use full screen or banner slider style. 您可以在许多库中使用全屏或横幅滑块样式。 Ex: 例如:

If you want create yourself you can use viewpager for image sliding. 如果要创建自己,可以使用viewpager进行图像滑动。

You can set OnItemClickListener based on selected item you can rediect to detail and show slider of image. 您可以基于选定的项目设置OnItemClickListener ,您可以重新选择其内容以显示和显示图像滑块。

Updated code : 更新的代码:

    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);
        }
    });

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM