Ich entwerfe eine UI, wo meine App 3 Registerkarten hat und ich habe es mit Fragmenten erstellt und ich dritte Registerkarte Ich brauche ListView mit Text und Bildern anzuzeigen.Ich kann die anzeigen Liste, aber wenn ich auf Zuhörer zu jedem Artikel schrieb die App zum Absturz starten und jetzt habe ich einen Fehler in nicht findViewById() function.I'll meinen Code mit diesem teilen .please mir hepl aus Contact.javakann nicht findViewById() in CustomListView mit Fragmenten
import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import android.content.res.TypedArray;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.ListFragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ListView;
import com.tutorialsbuzz.slidetablistview.R;
public class Contact extends ListFragment implements AdapterView.OnItemClickListener {
String[] member_names;
TypedArray profile_pics;
String[] statues;
String[] contactType;
List<RowItem> rowItems;
ListView mylistview;
@Override
public View onCreateView(LayoutInflater inflater,
@Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.contact, container, false);
return v;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
rowItems = new ArrayList<RowItem>();
member_names = getResources().getStringArray(R.array.Member_names);
profile_pics = getResources().obtainTypedArray(R.array.profile_pics);
statues = getResources().getStringArray(R.array.statues);
contactType = getResources().getStringArray(R.array.contactType);
for (int i = 0; i < member_names.length; i++) {
RowItem item = new RowItem(member_names[i],
profile_pics.getResourceId(i, -1), statues[i],
contactType[i]);
rowItems.add(item);
}
mylistview= (ListView) findViewById(android.R.id.list);
CustomAdapter adapter = new CustomAdapter(getActivity(), rowItems);
setListAdapter(adapter);
profile_pics.recycle();
mylistview.setOnItemClickListener(this);
}
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
super.onCreateOptionsMenu(menu, inflater);
getActivity().getMenuInflater().inflate(R.menu.menu_main, menu);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setHasOptionsMenu(true);
setHasOptionsMenu(true);
}
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if (position == 0) {
Intent myIntent = new Intent(view.getContext(), ummy.class);
startActivityForResult(myIntent, 0);
}
if (position == 1) {
Intent myIntent = new Intent(view.getContext(),ummy.class);
startActivityForResult(myIntent, 0);
}
if (position == 2) {
Intent myIntent = new Intent(view.getContext(), ummy.class);
startActivityForResult(myIntent, 0);
}
if (position == 3) {
Intent myIntent = new Intent(view.getContext(), ummy.class);
startActivityForResult(myIntent, 0);
}
if (position == 4) {
Intent myIntent = new Intent(view.getContext(), ummy.class);
startActivityForResult(myIntent, 0);
}
}
}
CustomAdapter.java
Contact.xml
<?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="match_parent"
android:orientation="vertical"
android:background="#ffffff" >
<ListView
android:id="@android:id/list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
<TextView
android:id="@android:id/empty"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</TextView>
</LinearLayout>
Vielen Dank pooja für mich aushelfen GetView .. –