I have a problem with the pictures when I use the search then the app always takes the first picture instead of the picture that belongs.
I added two pictures where you can see what I mean by "Adrenaline
".
Can someone help me by chance?
I would be very happy.
Sorry for my bad English.
package com.0000.00000;
import androidx.appcompat.app.AppCompatActivity;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import java.util.HashMap;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import android.content.Intent;
import android.net.Uri;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.AdapterView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class PerksActivity extends Activity {
private HashMap<String, Object> map_var = new HashMap<>();
private String saved = "";
private double length = 0;
private double r = 0;
private String value1 = "";
private String value2 = "";
private String value3 = "";
private String value4 = "";
private ArrayList<HashMap<String, Object>> map_list = new ArrayList<>();
private LinearLayout linear1;
private LinearLayout linear2;
private LinearLayout linear3;
private LinearLayout linear10;
private LinearLayout linear11;
private LinearLayout linear12;
private TextView textview4;
private AdView adview1;
private LinearLayout linear15;
private LinearLayout linear16;
private LinearLayout linear44;
private ListView listview1;
private EditText edittext1;
private LinearLayout linear929;
private TextView textview8;
private InterstitialAd admob;
private AdListener _admob_ad_listener;
private Intent page_intent = new Intent();
private AlertDialog.Builder popup;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.perks);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
linear3 = (LinearLayout) findViewById(R.id.linear3);
linear10 = (LinearLayout) findViewById(R.id.linear10);
linear11 = (LinearLayout) findViewById(R.id.linear11);
linear12 = (LinearLayout) findViewById(R.id.linear12);
textview4 = (TextView) findViewById(R.id.textview4);
adview1 = (AdView) findViewById(R.id.adview1);
linear15 = (LinearLayout) findViewById(R.id.linear15);
linear16 = (LinearLayout) findViewById(R.id.linear16);
linear44 = (LinearLayout) findViewById(R.id.linear44);
listview1 = (ListView) findViewById(R.id.listview1);
edittext1 = (EditText) findViewById(R.id.edittext1);
linear929 = (LinearLayout) findViewById(R.id.linear929);
textview8 = (TextView) findViewById(R.id.textview8);
popup = new AlertDialog.Builder(this);
listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> _param1, View _param2, int _param3, long _param4) {
final int _position = _param3;
if (_position == 0) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
if (_position == 1) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
if (_position == 2) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
}
});
edittext1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
final String _charSeq = _param1.toString();
map_list = new Gson().fromJson(saved, new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType());
length = map_list.size();
r = length - 1;
for(int _repeat17 = 0; _repeat17 < (int)(length); _repeat17++) {
value1 = map_list.get((int)r).get("a").toString();
value2 = map_list.get((int)r).get("b").toString();
value3 = map_list.get((int)r).get("c").toString();
if (!(_charSeq.length() > value1.length()) && value1.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
if (!(_charSeq.length() > value2.length()) && value2.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
if (!(_charSeq.length() > value3.length()) && value3.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
map_list.remove((int)(r));
}
}
}
r--;
}
listview1.setAdapter(new Listview1Adapter(map_list));
((BaseAdapter)listview1.getAdapter()).notifyDataSetChanged();
}
@Override
public void beforeTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
}
@Override
public void afterTextChanged(Editable _param1) {
}
});
_admob_ad_listener = new AdListener() {
@Override
public void onAdLoaded() {
admob.show();
}
@Override
public void onAdFailedToLoad(int _param1) {
final int _errorCode = _param1;
SketchwareUtil.showMessage(getApplicationContext(), "Werbung konnte nicht Geladen werden!!!".concat(String.valueOf((long)(_errorCode))));
}
@Override
public void onAdOpened() {
}
@Override
public void onAdClosed() {
}
};
}
private void initializeLogic() {
adview1.loadAd(new AdRequest.Builder().addTestDevice("0815")
.build());
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perksstriche));
map_var.put("b", getResources().getString(R.string.perksueberlebende));
map_var.put("c", getResources().getString(R.string.perksstriche02));
map_var.put("d", getResources().getString(R.string.perksinfopopupheadername));
map_var.put("e", getResources().getString(R.string.perksinfopopuptxtname));
map_list.add(map_var);
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perkablenkungname));
map_var.put("b", getResources().getString(R.string.perksueberlebendenadamfrancisname));
map_var.put("c", getResources().getString(R.string.perkslehrbarimblutnetzlevel30name));
map_var.put("d", getResources().getString(R.string.perkablenkungpopupheadername));
map_var.put("e", getResources().getString(R.string.perkablenkungpopuptxt));
map_list.add(map_var);
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perkadrenalinname));
map_var.put("b", getResources().getString(R.string.perksueberlebendenmegthomasname));
map_var.put("c", getResources().getString(R.string.perkslehrbarimblutnetzlevel40name));
map_var.put("d", getResources().getString(R.string.perkadrenalinpopupheadername));
map_var.put("e", getResources().getString(R.string.perkadrenalinpopuptxt));
map_list.add(map_var);
listview1.setAdapter(new Listview1Adapter(map_list));
((BaseAdapter)listview1.getAdapter()).notifyDataSetChanged();
saved = new Gson().toJson(map_list);
image_list.add(R.drawable.perk_ueberlebende);
image_list.add(R.drawable.adam_francis_perk_ablenkung);
image_list.add(R.drawable.meg_thomas_perk_adrenalin);
}
private ArrayList<Integer>
image_list = new ArrayList<>();
{
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
default:
break;
}
}
public class Listview1Adapter extends BaseAdapter {
ArrayList<HashMap<String, Object>> _data;
public Listview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
_data = _arr;
}
@Override
public int getCount() {
return _data.size();
}
@Override
public HashMap<String, Object> getItem(int _index) {
return _data.get(_index);
}
@Override
public long getItemId(int _index) {
return _index;
}
@Override
public View getView(final int _position, View _view, ViewGroup _viewGroup) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _v = _view;
if (_v == null) {
_v = _inflater.inflate(R.layout.perkssearch, null);
}
final LinearLayout linear1 = (LinearLayout) _v.findViewById(R.id.linear1);
final ImageView imageview1 = (ImageView) _v.findViewById(R.id.imageview1);
final LinearLayout linear2 = (LinearLayout) _v.findViewById(R.id.linear2);
final LinearLayout linear3 = (LinearLayout) _v.findViewById(R.id.linear3);
final TextView textview1 = (TextView) _v.findViewById(R.id.textview1);
final TextView textview2 = (TextView) _v.findViewById(R.id.textview2);
final TextView textview3 = (TextView) _v.findViewById(R.id.textview3);
textview1.setText(map_list.get((int)_position).get("a").toString());
textview2.setText(map_list.get((int)_position).get("b").toString());
textview3.setText(map_list.get((int)_position).get("c").toString());
imageview1.setImageResource
(image_list.get(_position));
if (textview2.getText().equals(getResources().getString(R.string.perksueberlebende)) ) {
textview2.setTextColor(0xFFFFFFFF);
}
if (textview2.getText().equals(getResources().getString(R.string.perksvonkeinezuordnungname)) ) {
textview2.setTextColor(0xFFFFFFFF);
}
if (textview2.getText().equals(getResources().getString(R.string.perksueberlebendendwightfairfieldname)) ) {
textview2.setTextColor(0xFF8BC34A);
}
return _v;
}
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}
} ```
Transfer this statement to the top
public class PerksActivity extends Activity {
private ArrayList<Integer> image_list = new ArrayList<>();
...
}
I see you have maintained your integer type casting but missed it when setting image resource in getview
.
imageview1.setImageResource(image_list.get((int)_position))
Hope it works
Nothing has changed.
import androidx.appcompat.app.AppCompatActivity;
import android.app.*;
import android.os.*;
import android.view.*;
import android.view.View.*;
import android.widget.*;
import android.content.*;
import android.graphics.*;
import android.media.*;
import android.net.*;
import android.text.*;
import android.util.*;
import android.webkit.*;
import android.animation.*;
import android.view.animation.*;
import java.util.*;
import java.text.*;
import java.util.HashMap;
import java.util.ArrayList;
import android.widget.LinearLayout;
import android.widget.TextView;
import com.google.android.gms.ads.AdView;
import com.google.android.gms.ads.AdRequest;
import android.widget.ListView;
import android.widget.ArrayAdapter;
import android.widget.BaseAdapter;
import android.widget.EditText;
import com.google.android.gms.ads.InterstitialAd;
import com.google.android.gms.ads.AdListener;
import android.content.Intent;
import android.net.Uri;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.AdapterView;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
public class PerksActivity extends Activity {
private ArrayList<Integer> image_list = new ArrayList<>();
private HashMap<String, Object> map_var = new HashMap<>();
private String saved = "";
private double length = 0;
private double r = 0;
private String value1 = "";
private String value2 = "";
private String value3 = "";
private String value4 = "";
private ArrayList<HashMap<String, Object>> map_list = new ArrayList<>();
private LinearLayout linear1;
private LinearLayout linear2;
private LinearLayout linear3;
private LinearLayout linear10;
private LinearLayout linear11;
private LinearLayout linear12;
private TextView textview4;
private AdView adview1;
private LinearLayout linear15;
private LinearLayout linear16;
private LinearLayout linear44;
private ListView listview1;
private EditText edittext1;
private LinearLayout linear929;
private TextView textview8;
private InterstitialAd admob;
private AdListener _admob_ad_listener;
private Intent page_intent = new Intent();
private AlertDialog.Builder popup;
@Override
protected void onCreate(Bundle _savedInstanceState) {
super.onCreate(_savedInstanceState);
setContentView(R.layout.perks);
initialize(_savedInstanceState);
initializeLogic();
}
private void initialize(Bundle _savedInstanceState) {
linear1 = (LinearLayout) findViewById(R.id.linear1);
linear2 = (LinearLayout) findViewById(R.id.linear2);
linear3 = (LinearLayout) findViewById(R.id.linear3);
linear10 = (LinearLayout) findViewById(R.id.linear10);
linear11 = (LinearLayout) findViewById(R.id.linear11);
linear12 = (LinearLayout) findViewById(R.id.linear12);
textview4 = (TextView) findViewById(R.id.textview4);
adview1 = (AdView) findViewById(R.id.adview1);
linear15 = (LinearLayout) findViewById(R.id.linear15);
linear16 = (LinearLayout) findViewById(R.id.linear16);
linear44 = (LinearLayout) findViewById(R.id.linear44);
listview1 = (ListView) findViewById(R.id.listview1);
edittext1 = (EditText) findViewById(R.id.edittext1);
linear929 = (LinearLayout) findViewById(R.id.linear929);
textview8 = (TextView) findViewById(R.id.textview8);
popup = new AlertDialog.Builder(this);
listview1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> _param1, View _param2, int _param3, long _param4) {
final int _position = _param3;
if (_position == 0) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
if (_position == 1) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
if (_position == 2) {
popup.setTitle(map_list.get((int)_position).get("d").toString());
popup.setMessage(map_list.get((int)_position).get("e").toString());
popup.setPositiveButton("Schliessen", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface _dialog, int _which) {
}
});
popup.create().show();
}
}
});
edittext1.addTextChangedListener(new TextWatcher() {
@Override
public void onTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
final String _charSeq = _param1.toString();
map_list = new Gson().fromJson(saved, new TypeToken<ArrayList<HashMap<String, Object>>>(){}.getType());
length = map_list.size();
r = length - 1;
for(int _repeat17 = 0; _repeat17 < (int)(length); _repeat17++) {
value1 = map_list.get((int)r).get("a").toString();
value2 = map_list.get((int)r).get("b").toString();
value3 = map_list.get((int)r).get("c").toString();
if (!(_charSeq.length() > value1.length()) && value1.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
if (!(_charSeq.length() > value2.length()) && value2.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
if (!(_charSeq.length() > value3.length()) && value3.toLowerCase().contains(_charSeq.toLowerCase())) {
}
else {
map_list.remove((int)(r));
}
}
}
r--;
}
listview1.setAdapter(new Listview1Adapter(map_list));
((BaseAdapter)listview1.getAdapter()).notifyDataSetChanged();
}
@Override
public void beforeTextChanged(CharSequence _param1, int _param2, int _param3, int _param4) {
}
@Override
public void afterTextChanged(Editable _param1) {
}
});
_admob_ad_listener = new AdListener() {
@Override
public void onAdLoaded() {
admob.show();
}
@Override
public void onAdFailedToLoad(int _param1) {
final int _errorCode = _param1;
SketchwareUtil.showMessage(getApplicationContext(), "Werbung konnte nicht Geladen werden!!!".concat(String.valueOf((long)(_errorCode))));
}
@Override
public void onAdOpened() {
}
@Override
public void onAdClosed() {
}
};
}
private void initializeLogic() {
adview1.loadAd(new AdRequest.Builder().addTestDevice("0815")
.build());
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perksstriche));
map_var.put("b", getResources().getString(R.string.perksueberlebende));
map_var.put("c", getResources().getString(R.string.perksstriche02));
map_var.put("d", getResources().getString(R.string.perksinfopopupheadername));
map_var.put("e", getResources().getString(R.string.perksinfopopuptxtname));
map_list.add(map_var);
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perkablenkungname));
map_var.put("b", getResources().getString(R.string.perksueberlebendenadamfrancisname));
map_var.put("c", getResources().getString(R.string.perkslehrbarimblutnetzlevel30name));
map_var.put("d", getResources().getString(R.string.perkablenkungpopupheadername));
map_var.put("e", getResources().getString(R.string.perkablenkungpopuptxt));
map_list.add(map_var);
map_var = new HashMap<>();
map_var.put("a", getResources().getString(R.string.perkadrenalinname));
map_var.put("b", getResources().getString(R.string.perksueberlebendenmegthomasname));
map_var.put("c", getResources().getString(R.string.perkslehrbarimblutnetzlevel40name));
map_var.put("d", getResources().getString(R.string.perkadrenalinpopupheadername));
map_var.put("e", getResources().getString(R.string.perkadrenalinpopuptxt));
map_list.add(map_var);
listview1.setAdapter(new Listview1Adapter(map_list));
((BaseAdapter)listview1.getAdapter()).notifyDataSetChanged();
saved = new Gson().toJson(map_list);
image_list.add(R.drawable.perk_ueberlebende);
image_list.add(R.drawable.adam_francis_perk_ablenkung);
image_list.add(R.drawable.meg_thomas_perk_adrenalin);
}
@Override
protected void onActivityResult(int _requestCode, int _resultCode, Intent _data) {
super.onActivityResult(_requestCode, _resultCode, _data);
switch (_requestCode) {
default:
break;
}
}
public class Listview1Adapter extends BaseAdapter {
ArrayList<HashMap<String, Object>> _data;
public Listview1Adapter(ArrayList<HashMap<String, Object>> _arr) {
_data = _arr;
}
@Override
public int getCount() {
return _data.size();
}
@Override
public HashMap<String, Object> getItem(int _index) {
return _data.get(_index);
}
@Override
public long getItemId(int _index) {
return _index;
}
@Override
public View getView(final int _position, View _view, ViewGroup _viewGroup) {
LayoutInflater _inflater = (LayoutInflater)getBaseContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View _v = _view;
if (_v == null) {
_v = _inflater.inflate(R.layout.perkssearch, null);
}
final LinearLayout linear1 = (LinearLayout) _v.findViewById(R.id.linear1);
final ImageView imageview1 = (ImageView) _v.findViewById(R.id.imageview1);
final LinearLayout linear2 = (LinearLayout) _v.findViewById(R.id.linear2);
final LinearLayout linear3 = (LinearLayout) _v.findViewById(R.id.linear3);
final TextView textview1 = (TextView) _v.findViewById(R.id.textview1);
final TextView textview2 = (TextView) _v.findViewById(R.id.textview2);
final TextView textview3 = (TextView) _v.findViewById(R.id.textview3);
textview1.setText(map_list.get((int)_position).get("a").toString());
textview2.setText(map_list.get((int)_position).get("b").toString());
textview3.setText(map_list.get((int)_position).get("c").toString());
imageview1.setImageResource(image_list.get((int)_position));
if (textview2.getText().equals(getResources().getString(R.string.perksueberlebende)) ) {
textview2.setTextColor(0xFFFFFFFF);
}
if (textview2.getText().equals(getResources().getString(R.string.perksvonkeinezuordnungname)) ) {
textview2.setTextColor(0xFFFFFFFF);
}
if (textview2.getText().equals(getResources().getString(R.string.perksueberlebendendwightfairfieldname)) ) {
textview2.setTextColor(0xFF8BC34A);
}
return _v;
}
}
@Deprecated
public void showMessage(String _s) {
Toast.makeText(getApplicationContext(), _s, Toast.LENGTH_SHORT).show();
}
@Deprecated
public int getLocationX(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[0];
}
@Deprecated
public int getLocationY(View _v) {
int _location[] = new int[2];
_v.getLocationInWindow(_location);
return _location[1];
}
@Deprecated
public int getRandom(int _min, int _max) {
Random random = new Random();
return random.nextInt(_max - _min + 1) + _min;
}
@Deprecated
public ArrayList<Double> getCheckedItemPositionsToArray(ListView _list) {
ArrayList<Double> _result = new ArrayList<Double>();
SparseBooleanArray _arr = _list.getCheckedItemPositions();
for (int _iIdx = 0; _iIdx < _arr.size(); _iIdx++) {
if (_arr.valueAt(_iIdx))
_result.add((double)_arr.keyAt(_iIdx));
}
return _result;
}
@Deprecated
public float getDip(int _input){
return TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, _input, getResources().getDisplayMetrics());
}
@Deprecated
public int getDisplayWidthPixels(){
return getResources().getDisplayMetrics().widthPixels;
}
@Deprecated
public int getDisplayHeightPixels(){
return getResources().getDisplayMetrics().heightPixels;
}
}
User contributions licensed under CC BY-SA 3.0