0

我有一些 50-60 图像。我想显示这些图像的标题列表,如果我单击一个项目,则必须打开与该项目相对应的图像和该图像的详细信息,然后应该通过滑动查看下一个图像。我有代码来显示列表视图,我需要代码来点击监听器和图像滑块,因为我是 android 开发的新手。我的代码是

FilmActivity.java , activity_film.xml , filmlist.xml

这些将使用链接的哈希图显示列表视图。现在我需要其余的代码。

电影活动.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

<?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>

电影列表.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>
4

2 回答 2

1

Setclicklistener 在您可以使用 github 库作为图像滑块之后您的项目。有许多库可以在其中使用全屏或横幅滑块样式。前任:

如果您想自己创建,可以使用 viewpager 进行图像滑动。

于 2018-09-29T07:02:38.997 回答
1

您可以OnItemClickListener根据所选项目进行设置,您可以重新调整为详细信息并显示图像滑块。

更新代码:

    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);
        }
    });
于 2018-09-29T07:11:22.300 回答