Also mein Layout Inflation in eine content_frame
besteht ->listview_fragment
->list_row_item
Kann nicht meine Listview füllen
Auf MainActivity
soll ich wählen, welche Prüfphase I angezeigt und Ich zwinge es für Debug Gründe
public class MainActivity extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener{
//region Properties
private GoogleMap map;
private static final int LAYOUT_CHOOSER = 123;
private static final String TAG="MainActivity";
//endregion
//region Methods
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main_activity);
if(LAYOUT_CHOOSER == 1){
Log.v(TAG, "Im on the MapMode");
getSupportFragmentManager().beginTransaction()
.add(R.id.content_frame, new SecurityMapFragment())
.commit();
}
else {
Log.v(TAG, "Im on the ListMode");
getSupportFragmentManager().beginTransaction()
.add(R.id.content_frame, new SecurityListFragment())
.commit();
}
Es wird die SecurityListFragment
Klasse
public class SecurityListFragment extends BaseFragment {
private TestAdapter mTestAdapter;
private SecurityResponse securityResponse;
private FetchDataInterface dataInterface;
public SecurityListFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
Log.v("ListFragment", "I entered the onCreateView!");
final View root = inflater.inflate(R.layout.security_listview_fragment, container, false);
Log.v("ListFragment", "rootView created");
//set adapter
ListView lista = (ListView) root.findViewById(R.id.listview_security);
lista.setAdapter(mTestAdapter);
Log.v("dasd", "asdasdasd");//for breakpoint usage
return root;
}
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
dataInterface = RetrofitUtils.createGsonRetrofitInterface();
RetrofitUtils.testGetPspDataFromApi(new Callback<SecurityResponse>() {
@Override
public void onResponse(Call<SecurityResponse> call, Response<SecurityResponse> response) {
if (response.isSuccessful()) {
securityResponse = response.body();
mTestAdapter = new TestAdapter(getActivity(), R.layout.list_security_row_item, securityResponse.features);
Log.v("ListFragment", "great success");
}
}
@Override
public void onFailure(Call<SecurityResponse> call, Throwable t) {
}
}, dataInterface);
Log.v("adasdadsa","asdasdasdasdasasdas");//more breakpoint usage
}
Es ist in der SecurityListFragment
Klasse aufrufen dass ich meinen Rückruf mache, um meine Daten mithilfe der Retrofit-Bibliothek zu erhalten. Der Callback funktioniert einwandfrei und die Daten sind nicht beschädigt. Ich habe es im anderen Modus getestet und kann Kartenobjekte entsprechend der angegebenen geografischen Position erstellen.
Meine TestAdapter
Klasse:
public class TestAdapter extends ArrayAdapter<Feature> {
protected Context mContext;
protected int layoutResourceId;
protected List<Feature> mSecurityResponse;
public TestAdapter(Context context, int resourceId, List<Feature> objects) {
super(context, resourceId, objects);
this.layoutResourceId = resourceId;
this.mContext = context;
this.mSecurityResponse = objects;
}
public View getView(int position, View convertView, ViewGroup parent){
ViewHolder viewHolder;
if(convertView==null){
// inflate the layout
LayoutInflater inflater = ((Activity) mContext).getLayoutInflater();
convertView = inflater.inflate(layoutResourceId, parent, false);
// well set up the ViewHolder
viewHolder = new ViewHolder();
viewHolder.distance = (TextView)convertView.findViewById(R.id.security_list_distance);
viewHolder.icon = (ImageView)convertView.findViewById(R.id.security_list_icon);
viewHolder.name = (TextView)convertView.findViewById(R.id.security_list_name);
viewHolder.description = (TextView)convertView.findViewById(R.id.security_list_description);
// store the holder with the view.
convertView.setTag(viewHolder);
}else{
// we've just avoided calling findViewById() on resource everytime
// just use the viewHolder
viewHolder = (ViewHolder) convertView.getTag();
}
// object item based on the position
Feature featureItem = mSecurityResponse.get(position);
// assign values if the object is not null
if(featureItem != null) {
// get the TextView from the ViewHolder and then set the text (item name) and tag (item ID) values
viewHolder.distance.setText("42"+ " km");
viewHolder.description.setText(featureItem.attributes.description);
viewHolder.name.setText(featureItem.attributes.name);
viewHolder.icon.setImageResource(R.mipmap.ic_launcher);
}
return convertView;
}
public static class ViewHolder{
public ImageView icon;
public TextView name;
public TextView description;
public TextView distance;
}
Fast sind vergessen haben hier die Layouts, die verwendet werden:
content_frame
Layout:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
</FrameLayout>
Die security_listview_fragment
:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<ListView
android:id="@+id/listview_security"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</FrameLayout>
Und die list_security_row_item
:
<?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">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/security_list_icon"/>
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:paddingLeft="20px">
<TextView
android:id="@+id/security_list_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
<TextView
android:id="@+id/security_list_description"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:id="@+id/security_list_distance"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
</LinearLayout>
Vielen Dank für Ihre Zeit.
tun, danken Ihnen für Ihre Hilfe. Ich werde bald nach dem Debuggen antworten. – diomonogatari
Es hat funktioniert, mein Layout ist voll, aber ich bin mir sicher, dass ich das schaffen kann. Danke für Ihre Zeit und Dankbarkeit. Ich verstehe jetzt, wie man mit dem Adapter und dem Rückruf umgeht. Danke vielmals. Markierte dich als Antwort;) – diomonogatari
willkommen ..... :) –