I have checked other questions but i don't know what i am doing wrong. I have android:id="@+id/list" and i am calling the right layout but still It gives an error saying, it must contain listview with id ...... fragment_contacts_list xml.
<android.support.v7.widget.RecyclerView 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:id="@+id/list" android:name="com.example.umerasif.chattris.ContactsFragment" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_marginLeft="16dp" android:layout_marginRight="16dp" app:layoutManager="LinearLayoutManager" tools:context="com.example.umerasif.chattris.ContactsFragment" tools:listitem="@layout/fragment_contacts" /> fragment_contacts.xml's code.
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="80dp" android:orientation="horizontal" android:weightSum="1" android:gravity="bottom"> <ImageView android:layout_width="100dp" android:layout_height="80dp" android:id="@+id/image" android:contentDescription="@string/Description" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceMedium" android:id="@+id/name" android:text="blabla" android:gravity="top" /> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/phone" android:text="blabalabab" /> and Code for my ListFragment.
public class ContactsFragment extends ListFragment { private static final String ARG_COLUMN_COUNT = "column-count"; private View lview; public ContactsFragment() { } @SuppressWarnings("unused") public static ContactsFragment newInstance(int columnCount) { ContactsFragment fragment = new ContactsFragment(); Bundle args = new Bundle(); args.putInt(ARG_COLUMN_COUNT, columnCount); fragment.setArguments(args); return fragment; } @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); DataBaseOperations hell = new DataBaseOperations(getActivity()); SQLiteDatabase db = hell.getReadableDatabase(); String[] columns = {mDatabase.Tableinfo.ID,mDatabase.Tableinfo.Contacts_phone,mDatabase.Tableinfo.Contacts_name}; Cursor Contacts = db.query(mDatabase.Tableinfo.contacts,columns,null,null,null,null,null); db.close(); Contacts.close(); hell.close(); String[] from = {mDatabase.Tableinfo.Contacts_phone,mDatabase.Tableinfo.Contacts_name}; int[] to = {R.id.phone,R.id.name}; ContactsAdapter adapter = new ContactsAdapter(getActivity(),R.layout.fragment_contacts,Contacts,from,to,0); setListAdapter(adapter); } public class ContactsAdapter extends SimpleCursorAdapter{ public ContactsAdapter(Context context, int layout, Cursor c, String[] from, int[] to, int flags) { super(context, layout, c, from, to, flags); } } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { lview = inflater.inflate(R.layout.fragment_contacts_list, container, false); return lview; }
No comments:
Post a Comment