I have a listview in a fragment. I want to set those multiple textviews. So how should i set the custom adapter. I am new at android and need some help.
public class Tab1 extends Fragment {
@Override
public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.tab_1, container, false);
ListView listView = (ListView)v.findViewById(R.id.listOfTasks);
//need to pass 2 string arrays.
//string[] s1;
//string[] s2;
ListAdapter taskAdapter = new TaskCustomAdapter( //here..... );
listView.setAdapter(taskAdapter);
listView.setOnItemClickListener(
new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
String task = String.valueOf(parent.getItemAtPosition(position));
Toast.makeText(getActivity(),task,Toast.LENGTH_SHORT).show();
}
}
);
return v;
}
}
this is my list view with multiples textfields.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="60dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/task_title"
android:layout_gravity="left|center_vertical"
android:layout_marginLeft="20dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="@+id/task_subtitle"
android:layout_gravity="center" />
</FrameLayout>
</LinearLayout>
And my present adapter is :
public class TaskCustomAdapter extends ArrayAdapter<String>{
public TaskCustomAdapter(Context context,String[] tasks) {
super(context,R.layout.taskfragment,tasks);
}
@Override
public View getView(int position, View convertView, ViewGroup parent){
LayoutInflater task_inflater = LayoutInflater.from(getContext());
View customView = task_inflater.inflate(R.layout.taskfragment,parent,false);
String task = getItem(position);
TextView title = (TextView)customView.findViewById(R.id.task_title);
title.setText(task);
return customView;
}
}
thanks!