Beginn mit Listview in Listview
This commit is contained in:
parent
a74eb62b6b
commit
362b41fd13
@ -59,6 +59,11 @@ public class AllIOsFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getCount() {
|
public int getCount() {
|
||||||
|
/**int count=0;
|
||||||
|
for(int i = 0; i < mainActivity.xml.getDeviceNames().size();i++){
|
||||||
|
count += ((List<String>)mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i)).get("pins")).size();
|
||||||
|
}
|
||||||
|
return count;*/
|
||||||
return mainActivity.xml.getDeviceNames().size();
|
return mainActivity.xml.getDeviceNames().size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,32 +82,44 @@ public class AllIOsFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public View getView(final int i, View view,
|
public View getView(final int i, View view,
|
||||||
final ViewGroup viewGroup) {
|
final ViewGroup viewGroup) {
|
||||||
/*if(mainActivity.uebergabe.read(mainActivity.xml.
|
|
||||||
getDeviceNames().get(i)).equals("TRUE")) {
|
|
||||||
image=R.drawable.green_signal;
|
|
||||||
}else if (mainActivity.uebergabe.read(mainActivity.xml.
|
|
||||||
getDeviceNames().get(i)).equals("FALSE")) {
|
|
||||||
image = R.drawable.red_signal;
|
|
||||||
}
|
|
||||||
else{*/
|
|
||||||
image = R.drawable.off_signal;
|
|
||||||
//}
|
|
||||||
if (mainActivity.favorite.getFavorites().contains(
|
|
||||||
mainActivity.xml.getDeviceNames().get(i))) {
|
|
||||||
favoriteImage = android.R.drawable.btn_star_big_on;
|
|
||||||
} else {
|
|
||||||
favoriteImage = android.R.drawable.btn_star_big_off;
|
|
||||||
}
|
|
||||||
view = getLayoutInflater().inflate(R.layout.listview_layout,
|
view = getLayoutInflater().inflate(R.layout.listview_layout,
|
||||||
null);
|
null);
|
||||||
ImageView imageView = (ImageView) view.findViewById(
|
ImageView imageView = (ImageView) view.findViewById(
|
||||||
R.id.images);
|
R.id.images);
|
||||||
TextView textViewName = (TextView) view.findViewById(
|
TextView textViewName = (TextView) view.findViewById(
|
||||||
R.id.textName);
|
R.id.textName);
|
||||||
TextView textViewState = (TextView) view.findViewById(
|
TextView textViewPin = (TextView) view.findViewById(
|
||||||
R.id.textState);
|
R.id.textPin);
|
||||||
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
ImageView buttonViewFavoriten = (ImageView) view.findViewById(
|
||||||
R.id.imageButtonFavoriten);
|
R.id.imageButtonFavoriten);
|
||||||
|
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
||||||
|
get(i), new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(final JSONObject response) {
|
||||||
|
try {
|
||||||
|
String firstpinvalue = response.getJSONObject("state").getString(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
if(firstpinvalue.equals("1")) {
|
||||||
|
image=R.drawable.green_signal;
|
||||||
|
}else if (firstpinvalue.equals("0")) {
|
||||||
|
image = R.drawable.red_signal;
|
||||||
|
} else{ image = R.drawable.off_signal; }
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
image = R.drawable.off_signal;
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (mainActivity.favorite.getFavorites().contains(
|
||||||
|
mainActivity.xml.getDeviceNames().get(i))) {
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_on;
|
||||||
|
} else {
|
||||||
|
favoriteImage = android.R.drawable.btn_star_big_off;
|
||||||
|
}
|
||||||
|
|
||||||
buttonViewFavoriten.setOnClickListener(
|
buttonViewFavoriten.setOnClickListener(
|
||||||
new View.OnClickListener() {
|
new View.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
@ -136,11 +153,11 @@ public class AllIOsFragment extends Fragment {
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
imageView.setImageResource(image);
|
|
||||||
textViewName.setText(mainActivity.xml.getDeviceNames().get(i));
|
|
||||||
//TextView_State.setText(mainActivity.uebergabe.read(
|
//TextView_State.setText(mainActivity.uebergabe.read(
|
||||||
// mainActivity.xml.getDeviceNames().get(i)));
|
// mainActivity.xml.getDeviceNames().get(i)));
|
||||||
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
/** mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
||||||
get(i), new Response.Listener<JSONObject>() {
|
get(i), new Response.Listener<JSONObject>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(final JSONObject response) {
|
public void onResponse(final JSONObject response) {
|
||||||
@ -151,12 +168,12 @@ public class AllIOsFragment extends Fragment {
|
|||||||
List<String> pinnames = (List<String>) portinfo.get("pins");
|
List<String> pinnames = (List<String>) portinfo.get("pins");
|
||||||
String firstpinname = pinnames.get(0);
|
String firstpinname = pinnames.get(0);
|
||||||
int groesse = pinnames.size();
|
int groesse = pinnames.size();
|
||||||
/** for(String pinname : pinnames){
|
for(String pinname : pinnames){
|
||||||
|
|
||||||
}//anstatt for mit laufvariable
|
}//anstatt for mit laufvariable
|
||||||
for(int h; h < pinnames.size();h++){
|
for(int h; h < pinnames.size();h++){
|
||||||
String pinname = pinnames.get(h);
|
String pinname = pinnames.get(h);
|
||||||
}*/
|
}
|
||||||
String firstpinvalue = pins.getString(firstpinname);
|
String firstpinvalue = pins.getString(firstpinname);
|
||||||
textViewState.setText(firstpinvalue);
|
textViewState.setText(firstpinvalue);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
@ -164,7 +181,9 @@ public class AllIOsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
});
|
});*/
|
||||||
|
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
textViewName.setText(mainActivity.xml.getDeviceNames().get(i));
|
||||||
buttonViewFavoriten.setImageResource(favoriteImage);
|
buttonViewFavoriten.setImageResource(favoriteImage);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,156 @@
|
|||||||
|
package com.example.aped.ui.all_IOs;
|
||||||
|
|
||||||
|
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.BaseAdapter;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.ListView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import androidx.fragment.app.Fragment;
|
||||||
|
|
||||||
|
import com.android.volley.Response;
|
||||||
|
import com.example.aped.MainActivity;
|
||||||
|
import com.example.aped.R;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
|
public class AllIOsFragment2 extends Fragment {
|
||||||
|
/**
|
||||||
|
* Einbinden der MainActivity.
|
||||||
|
*/
|
||||||
|
private MainActivity mainActivity;
|
||||||
|
/**
|
||||||
|
* Genutzt für Signallampe.
|
||||||
|
*/
|
||||||
|
private int image;
|
||||||
|
/**
|
||||||
|
* Genutzt für Favoriten icons.
|
||||||
|
*/
|
||||||
|
private int favoriteImage;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param inflater
|
||||||
|
* @param container
|
||||||
|
* @param savedInstanceState
|
||||||
|
* @return view
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public View onCreateView(final LayoutInflater inflater,
|
||||||
|
final ViewGroup container,
|
||||||
|
final Bundle savedInstanceState) {
|
||||||
|
this.mainActivity = (MainActivity) getActivity();
|
||||||
|
View view = inflater.inflate(R.layout.listview_layout, container,
|
||||||
|
false);
|
||||||
|
ListView lv = (ListView) view.findViewById(R.id.idListViewPins);
|
||||||
|
CustomAdapter customAdapter = new CustomAdapter();
|
||||||
|
lv.setAdapter(customAdapter);
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomAdapter extends BaseAdapter {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCount() {
|
||||||
|
int count=0;
|
||||||
|
count += ((List<String>)mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(1)).get("pins")).size();
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Object getItem(final int position) {
|
||||||
|
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public long getItemId(final int position) {
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public View getView(final int i, View view,
|
||||||
|
final ViewGroup viewGroup) {
|
||||||
|
view = getLayoutInflater().inflate(R.layout.listview2_layout,
|
||||||
|
null);
|
||||||
|
ImageView imageView = (ImageView) view.findViewById(
|
||||||
|
R.id.images);
|
||||||
|
TextView textViewPin = (TextView) view.findViewById(
|
||||||
|
R.id.textPin);
|
||||||
|
mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
||||||
|
get(i), new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(final JSONObject response) {
|
||||||
|
try {
|
||||||
|
String firstpinvalue = response.getJSONObject("state").getString(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
if(firstpinvalue.equals("1")) {
|
||||||
|
image=R.drawable.green_signal;
|
||||||
|
}else if (firstpinvalue.equals("0")) {
|
||||||
|
image = R.drawable.red_signal;
|
||||||
|
} else{ image = R.drawable.off_signal; }
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
image = R.drawable.off_signal;
|
||||||
|
imageView.setImageResource(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Verarbeitung/ Änderung der Zustände DO
|
||||||
|
*/
|
||||||
|
imageView.setOnClickListener(new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
public void onClick(final View view) {
|
||||||
|
Toast.makeText(getContext(), "Click auf: " + i,
|
||||||
|
Toast.LENGTH_SHORT).show();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//TextView_State.setText(mainActivity.uebergabe.read(
|
||||||
|
// mainActivity.xml.getDeviceNames().get(i)));
|
||||||
|
/** mainActivity.uebergabe.read(mainActivity.xml.getDeviceNames().
|
||||||
|
get(i), new Response.Listener<JSONObject>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(final JSONObject response) {
|
||||||
|
try {
|
||||||
|
JSONObject pins = response.getJSONObject("state");
|
||||||
|
String devicename = mainActivity.xml.getDeviceNames().get(i);
|
||||||
|
Dictionary<String,Object> portinfo = mainActivity.xml.getPort(devicename);
|
||||||
|
List<String> pinnames = (List<String>) portinfo.get("pins");
|
||||||
|
String firstpinname = pinnames.get(0);
|
||||||
|
int groesse = pinnames.size();
|
||||||
|
for(String pinname : pinnames){
|
||||||
|
|
||||||
|
}//anstatt for mit laufvariable
|
||||||
|
for(int h; h < pinnames.size();h++){
|
||||||
|
String pinname = pinnames.get(h);
|
||||||
|
}
|
||||||
|
String firstpinvalue = pins.getString(firstpinname);
|
||||||
|
textViewState.setText(firstpinvalue);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
textViewPin.setText(((List<String>) (mainActivity.xml.getPort(mainActivity.xml.getDeviceNames().get(i))).get("pins")).get(0));
|
||||||
|
return view;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user