Skip to content

Instantly share code, notes, and snippets.

@nomunomu0504
Last active August 29, 2017 13:24
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save nomunomu0504/713d5946c613b81e267eac243e44da9f to your computer and use it in GitHub Desktop.
Save nomunomu0504/713d5946c613b81e267eac243e44da9f to your computer and use it in GitHub Desktop.
class ListView_Adapter extends BaseAdapter {
private Context context;
private LayoutInflater layoutInflater = null;
private ArrayList<Integer> Images = null;
private ArrayList<String> sentences = new ArrayList<>() {
{
put("sentences: xxxxx");
put("sentences: yyyyy");
}
}
private ListView1_Adapter listview1_adapter;
public ListView_Adapter(Context context) {
this.context = context;
this.layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setImagelist(ArrayList<Integer> images) {
this.Images = images;
}
@Override
public int getCount() {
return Images == null ? 0 : Images.size() ;
}
@Override
public Object getItem(int position) {
return Images.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = layoutInflater.inflate(R.layout.sub, parent, false);
ListView listview = (ListView) convertView.findViewById(R.id.listView);
((ImageView) convertView.findViewById(R.id.imageView1)).setImageResource(getItem(position));
listview1_adapter = new ListView1_Adapter(context);
listview1_adapter.setSentences(sentences);
listview1.setAdapter(listview1_adapter);
return convertView;
}
}
class ListView1_Adapter extends BaseAdapter {
private Context context;
private LayoutInflater layoutInflater = null;
private ArrayList<String> sentences = null;
public ListView1_Adapter(Context context) {
this.context = context;
this.layoutInflater = (LayoutInflater)context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
public void setSentences(ArrayList<String> sentences) {
this.sentences = sentences;
}
@Override
public int getCount() {
return sentences == null ? 0 : sentences.size() ;
}
@Override
public Object getItem(int position) {
return sentences.get(position);
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
convertView = layoutInflater.inflate(R.layout.sub2, parent, false);
ListView listview1 = (ListView) convertView.findViewById(R.id.listView1);
((TextView) convertView.findViewById(R.id.textView1)).setText(getItem(position));
return convertView;
}
}
public class main extends Activity {
private ListAdapter listAdapter;
private ListView listView;
private ArrayList<Integer> images = new ArrayList<>() {
{
put(R.drawable.xxxxxx);
put(R.drawable.yyyyyy);
}
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
listView = (ListView)findViewById(R.id.listView);
listAdapter = new ListView_Adapter(this);
listAdapter.setImagelist(images);
listView.setAdapter(listAdapter);
}
}
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:baselineAligned="false"
android:orientation="vertical">
<ListView
android:id="@+id/listView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="1">
<ImageView
android:id="@+id/imageView1"
android:layout_width="171dp"
android:layout_height="match_parent"
android:scaleType="center"
app:srcCompat="@drawable/japanese" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<ListView
android:id="@+id/listView1"
android:layout_width="432dp"
android:layout_height="match_parent"
android:textSize="12sp" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:textSize="30sp" />
</LinearLayout>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment