Searching ListView with showing wrong items
When I search an event it works, but when I click on the event it gives me the wrong item on the ListView
even though it changed the ListView
.
What should I do to make it work ?
public class Searchable extends Activity {
ListView lv;
SearchView sv;
String names={"Gratis mad på Frederik Bajers vej 7","Gratis æbleskiver på basis","Growstack: Vertical Wednesday #5","Videoredigerings kursus","Kursus i Psykisk førstehjælp - modul 1","Nye øjne på jobsøgningen","Vr-turnering i CS samt racersimulator", "Nytårsfest med bowling og spisning- kom og tag kegler","Temamøde om patenter og immaterielle rettigheder i Aalborg","Stationsnær byfortætning- kan vi få det hele?", "Den Gode, den Onde og den Grundige kode", "Foredrag med Kurt Kragh - Kan du tænke som en morder?", "SAVEUS koncert","Varm jazz på en kold vinterdag", "Julekoncert med trompetisten Per Nielsen i Brødrenmenighedens Krike i Christiansfeld", "Hygge Friday 2nd edition","Filmaften: Fantastiske skabninger 2- Grindelwalds forbrydelser","Boblesmagning- find dine nytårsbobler", "Jan Gintberg: Hemmeligheden bag den gode ide","Netværk og uopfordret jobsøgning", "The Magic og Science","2nd Nordic-Italian Polymer Future workshop" };
int images={R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,R.drawable.b5,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b10,R.drawable.b11,R.drawable.b12,R.drawable.b13,R.drawable.b14,R.drawable.b15,R.drawable.b16,R.drawable.b17,R.drawable.b18,R.drawable.b19,R.drawable.b20,R.drawable.b21,R.drawable.b22};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchable);
lv=(ListView) findViewById(R.id.listView1);
sv=(SearchView) findViewById(R.id.searchView1);
//ADASPTER
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
Intent intent= new Intent(view.getContext(),Activity1.class);
startActivityForResult(intent,0);
MainActivity.editClick++;
}
if(position==1){
Intent intent= new Intent(view.getContext(),Activity2.class);
startActivityForResult(intent,1);
MainActivity.editClick++;
}
if(position==2){
Intent intent= new Intent(view.getContext(),Activity3.class);
startActivityForResult(intent,2);
MainActivity.editClick++;
}
if(position==3){
Intent intent= new Intent(view.getContext(),Activity4.class);
startActivityForResult(intent,3);
MainActivity.editClick++;
}
if(position==4){
Intent intent= new Intent(view.getContext(),Activity5.class);
startActivityForResult(intent,4);
MainActivity.editClick++;
}
if(position==5){
Intent intent= new Intent(view.getContext(),Activity6.class);
startActivityForResult(intent,5);
MainActivity.editClick++;
}
if(position==6){
Intent intent= new Intent(view.getContext(),Activity7.class);
startActivityForResult(intent,6);
MainActivity.editClick++;
}
if(position==7){
Intent intent= new Intent(view.getContext(),Activity8.class);
startActivityForResult(intent,7);
MainActivity.editClick++;
}
if(position==8){
Intent intent= new Intent(view.getContext(),Activity9.class);
startActivityForResult(intent,8);
MainActivity.editClick++;
}
if(position==9){
Intent intent= new Intent(view.getContext(),Activity10.class);
startActivityForResult(intent,9);
MainActivity.editClick++;
}
if(position==10){
Intent intent= new Intent(view.getContext(),Activity11.class);
startActivityForResult(intent,10);
MainActivity.editClick++;
}
if(position==11){
Intent intent= new Intent(view.getContext(),Activity12.class);
startActivityForResult(intent,11);
MainActivity.editClick++;
}
if(position==12){
Intent intent= new Intent(view.getContext(),Activity13.class);
startActivityForResult(intent,12);
MainActivity.editClick++;
}
if(position==13){
Intent intent= new Intent(view.getContext(),Activity14.class);
startActivityForResult(intent,13);
MainActivity.editClick++;
}
if(position==14){
Intent intent= new Intent(view.getContext(),Activity15.class);
startActivityForResult(intent,14);
MainActivity.editClick++;
}
if(position==15){
Intent intent= new Intent(view.getContext(),Activity16.class);
startActivityForResult(intent,15);
MainActivity.editClick++;
}
if(position==16){
Intent intent= new Intent(view.getContext(),Activity17.class);
startActivityForResult(intent,16);
MainActivity.editClick++;
}
if(position==17){
Intent intent= new Intent(view.getContext(),Activity18.class);
startActivityForResult(intent,17);
MainActivity.editClick++;
}
if(position==18){
Intent intent= new Intent(view.getContext(),Activity19.class);
startActivityForResult(intent,18);
MainActivity.editClick++;
}
if(position==19){
Intent intent= new Intent(view.getContext(),Activity20.class);
startActivityForResult(intent,19);
MainActivity.editClick++;
}
if(position==20){
Intent intent= new Intent(view.getContext(),Activity21.class);
startActivityForResult(intent,20);
MainActivity.editClick++;
}
if(position==21){
Intent intent= new Intent(view.getContext(),Activity22.class);
startActivityForResult(intent,21);
MainActivity.editClick++;
}
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String query) {
// TODO Auto-generated method stub
adapter.getFilter().filter(query);
return false;
}
});
}
private ArrayList<ArrayListe> getPlayers()
{
ArrayList<ArrayListe> ArrayLister=new ArrayList<ArrayListe>();
ArrayListe p;
for(int i=0;i<names.length;i++)
{
p=new ArrayListe(names[i], images[i]);
ArrayLister.add(p);
}
return ArrayLister;
}
}
and the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGray"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorWhite">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="327dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:clickable="true"
app:cardBackgroundColor="@color/colorGray"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
tools:layout_editor_absoluteX="31dp"
tools:layout_editor_absoluteY="0dp">
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_alignRight="@+id/listView1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:iconifiedByDefault="false"
android:paddingLeft="-15dp"
android:queryHint="Søg..">
</SearchView>
</android.support.v7.widget.CardView>
</RelativeLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:background="@color/colorGray"
android:backgroundTint="@color/colorGray"
android:divider="@color/colorGray"
android:dividerHeight="5dp" />
</RelativeLayout
.................................................................... .. . . . . . . . . . . . . . . . . . .
android listview search searchview
add a comment |
When I search an event it works, but when I click on the event it gives me the wrong item on the ListView
even though it changed the ListView
.
What should I do to make it work ?
public class Searchable extends Activity {
ListView lv;
SearchView sv;
String names={"Gratis mad på Frederik Bajers vej 7","Gratis æbleskiver på basis","Growstack: Vertical Wednesday #5","Videoredigerings kursus","Kursus i Psykisk førstehjælp - modul 1","Nye øjne på jobsøgningen","Vr-turnering i CS samt racersimulator", "Nytårsfest med bowling og spisning- kom og tag kegler","Temamøde om patenter og immaterielle rettigheder i Aalborg","Stationsnær byfortætning- kan vi få det hele?", "Den Gode, den Onde og den Grundige kode", "Foredrag med Kurt Kragh - Kan du tænke som en morder?", "SAVEUS koncert","Varm jazz på en kold vinterdag", "Julekoncert med trompetisten Per Nielsen i Brødrenmenighedens Krike i Christiansfeld", "Hygge Friday 2nd edition","Filmaften: Fantastiske skabninger 2- Grindelwalds forbrydelser","Boblesmagning- find dine nytårsbobler", "Jan Gintberg: Hemmeligheden bag den gode ide","Netværk og uopfordret jobsøgning", "The Magic og Science","2nd Nordic-Italian Polymer Future workshop" };
int images={R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,R.drawable.b5,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b10,R.drawable.b11,R.drawable.b12,R.drawable.b13,R.drawable.b14,R.drawable.b15,R.drawable.b16,R.drawable.b17,R.drawable.b18,R.drawable.b19,R.drawable.b20,R.drawable.b21,R.drawable.b22};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchable);
lv=(ListView) findViewById(R.id.listView1);
sv=(SearchView) findViewById(R.id.searchView1);
//ADASPTER
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
Intent intent= new Intent(view.getContext(),Activity1.class);
startActivityForResult(intent,0);
MainActivity.editClick++;
}
if(position==1){
Intent intent= new Intent(view.getContext(),Activity2.class);
startActivityForResult(intent,1);
MainActivity.editClick++;
}
if(position==2){
Intent intent= new Intent(view.getContext(),Activity3.class);
startActivityForResult(intent,2);
MainActivity.editClick++;
}
if(position==3){
Intent intent= new Intent(view.getContext(),Activity4.class);
startActivityForResult(intent,3);
MainActivity.editClick++;
}
if(position==4){
Intent intent= new Intent(view.getContext(),Activity5.class);
startActivityForResult(intent,4);
MainActivity.editClick++;
}
if(position==5){
Intent intent= new Intent(view.getContext(),Activity6.class);
startActivityForResult(intent,5);
MainActivity.editClick++;
}
if(position==6){
Intent intent= new Intent(view.getContext(),Activity7.class);
startActivityForResult(intent,6);
MainActivity.editClick++;
}
if(position==7){
Intent intent= new Intent(view.getContext(),Activity8.class);
startActivityForResult(intent,7);
MainActivity.editClick++;
}
if(position==8){
Intent intent= new Intent(view.getContext(),Activity9.class);
startActivityForResult(intent,8);
MainActivity.editClick++;
}
if(position==9){
Intent intent= new Intent(view.getContext(),Activity10.class);
startActivityForResult(intent,9);
MainActivity.editClick++;
}
if(position==10){
Intent intent= new Intent(view.getContext(),Activity11.class);
startActivityForResult(intent,10);
MainActivity.editClick++;
}
if(position==11){
Intent intent= new Intent(view.getContext(),Activity12.class);
startActivityForResult(intent,11);
MainActivity.editClick++;
}
if(position==12){
Intent intent= new Intent(view.getContext(),Activity13.class);
startActivityForResult(intent,12);
MainActivity.editClick++;
}
if(position==13){
Intent intent= new Intent(view.getContext(),Activity14.class);
startActivityForResult(intent,13);
MainActivity.editClick++;
}
if(position==14){
Intent intent= new Intent(view.getContext(),Activity15.class);
startActivityForResult(intent,14);
MainActivity.editClick++;
}
if(position==15){
Intent intent= new Intent(view.getContext(),Activity16.class);
startActivityForResult(intent,15);
MainActivity.editClick++;
}
if(position==16){
Intent intent= new Intent(view.getContext(),Activity17.class);
startActivityForResult(intent,16);
MainActivity.editClick++;
}
if(position==17){
Intent intent= new Intent(view.getContext(),Activity18.class);
startActivityForResult(intent,17);
MainActivity.editClick++;
}
if(position==18){
Intent intent= new Intent(view.getContext(),Activity19.class);
startActivityForResult(intent,18);
MainActivity.editClick++;
}
if(position==19){
Intent intent= new Intent(view.getContext(),Activity20.class);
startActivityForResult(intent,19);
MainActivity.editClick++;
}
if(position==20){
Intent intent= new Intent(view.getContext(),Activity21.class);
startActivityForResult(intent,20);
MainActivity.editClick++;
}
if(position==21){
Intent intent= new Intent(view.getContext(),Activity22.class);
startActivityForResult(intent,21);
MainActivity.editClick++;
}
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String query) {
// TODO Auto-generated method stub
adapter.getFilter().filter(query);
return false;
}
});
}
private ArrayList<ArrayListe> getPlayers()
{
ArrayList<ArrayListe> ArrayLister=new ArrayList<ArrayListe>();
ArrayListe p;
for(int i=0;i<names.length;i++)
{
p=new ArrayListe(names[i], images[i]);
ArrayLister.add(p);
}
return ArrayLister;
}
}
and the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGray"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorWhite">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="327dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:clickable="true"
app:cardBackgroundColor="@color/colorGray"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
tools:layout_editor_absoluteX="31dp"
tools:layout_editor_absoluteY="0dp">
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_alignRight="@+id/listView1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:iconifiedByDefault="false"
android:paddingLeft="-15dp"
android:queryHint="Søg..">
</SearchView>
</android.support.v7.widget.CardView>
</RelativeLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:background="@color/colorGray"
android:backgroundTint="@color/colorGray"
android:divider="@color/colorGray"
android:dividerHeight="5dp" />
</RelativeLayout
.................................................................... .. . . . . . . . . . . . . . . . . . .
android listview search searchview
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
1
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31
add a comment |
When I search an event it works, but when I click on the event it gives me the wrong item on the ListView
even though it changed the ListView
.
What should I do to make it work ?
public class Searchable extends Activity {
ListView lv;
SearchView sv;
String names={"Gratis mad på Frederik Bajers vej 7","Gratis æbleskiver på basis","Growstack: Vertical Wednesday #5","Videoredigerings kursus","Kursus i Psykisk førstehjælp - modul 1","Nye øjne på jobsøgningen","Vr-turnering i CS samt racersimulator", "Nytårsfest med bowling og spisning- kom og tag kegler","Temamøde om patenter og immaterielle rettigheder i Aalborg","Stationsnær byfortætning- kan vi få det hele?", "Den Gode, den Onde og den Grundige kode", "Foredrag med Kurt Kragh - Kan du tænke som en morder?", "SAVEUS koncert","Varm jazz på en kold vinterdag", "Julekoncert med trompetisten Per Nielsen i Brødrenmenighedens Krike i Christiansfeld", "Hygge Friday 2nd edition","Filmaften: Fantastiske skabninger 2- Grindelwalds forbrydelser","Boblesmagning- find dine nytårsbobler", "Jan Gintberg: Hemmeligheden bag den gode ide","Netværk og uopfordret jobsøgning", "The Magic og Science","2nd Nordic-Italian Polymer Future workshop" };
int images={R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,R.drawable.b5,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b10,R.drawable.b11,R.drawable.b12,R.drawable.b13,R.drawable.b14,R.drawable.b15,R.drawable.b16,R.drawable.b17,R.drawable.b18,R.drawable.b19,R.drawable.b20,R.drawable.b21,R.drawable.b22};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchable);
lv=(ListView) findViewById(R.id.listView1);
sv=(SearchView) findViewById(R.id.searchView1);
//ADASPTER
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
Intent intent= new Intent(view.getContext(),Activity1.class);
startActivityForResult(intent,0);
MainActivity.editClick++;
}
if(position==1){
Intent intent= new Intent(view.getContext(),Activity2.class);
startActivityForResult(intent,1);
MainActivity.editClick++;
}
if(position==2){
Intent intent= new Intent(view.getContext(),Activity3.class);
startActivityForResult(intent,2);
MainActivity.editClick++;
}
if(position==3){
Intent intent= new Intent(view.getContext(),Activity4.class);
startActivityForResult(intent,3);
MainActivity.editClick++;
}
if(position==4){
Intent intent= new Intent(view.getContext(),Activity5.class);
startActivityForResult(intent,4);
MainActivity.editClick++;
}
if(position==5){
Intent intent= new Intent(view.getContext(),Activity6.class);
startActivityForResult(intent,5);
MainActivity.editClick++;
}
if(position==6){
Intent intent= new Intent(view.getContext(),Activity7.class);
startActivityForResult(intent,6);
MainActivity.editClick++;
}
if(position==7){
Intent intent= new Intent(view.getContext(),Activity8.class);
startActivityForResult(intent,7);
MainActivity.editClick++;
}
if(position==8){
Intent intent= new Intent(view.getContext(),Activity9.class);
startActivityForResult(intent,8);
MainActivity.editClick++;
}
if(position==9){
Intent intent= new Intent(view.getContext(),Activity10.class);
startActivityForResult(intent,9);
MainActivity.editClick++;
}
if(position==10){
Intent intent= new Intent(view.getContext(),Activity11.class);
startActivityForResult(intent,10);
MainActivity.editClick++;
}
if(position==11){
Intent intent= new Intent(view.getContext(),Activity12.class);
startActivityForResult(intent,11);
MainActivity.editClick++;
}
if(position==12){
Intent intent= new Intent(view.getContext(),Activity13.class);
startActivityForResult(intent,12);
MainActivity.editClick++;
}
if(position==13){
Intent intent= new Intent(view.getContext(),Activity14.class);
startActivityForResult(intent,13);
MainActivity.editClick++;
}
if(position==14){
Intent intent= new Intent(view.getContext(),Activity15.class);
startActivityForResult(intent,14);
MainActivity.editClick++;
}
if(position==15){
Intent intent= new Intent(view.getContext(),Activity16.class);
startActivityForResult(intent,15);
MainActivity.editClick++;
}
if(position==16){
Intent intent= new Intent(view.getContext(),Activity17.class);
startActivityForResult(intent,16);
MainActivity.editClick++;
}
if(position==17){
Intent intent= new Intent(view.getContext(),Activity18.class);
startActivityForResult(intent,17);
MainActivity.editClick++;
}
if(position==18){
Intent intent= new Intent(view.getContext(),Activity19.class);
startActivityForResult(intent,18);
MainActivity.editClick++;
}
if(position==19){
Intent intent= new Intent(view.getContext(),Activity20.class);
startActivityForResult(intent,19);
MainActivity.editClick++;
}
if(position==20){
Intent intent= new Intent(view.getContext(),Activity21.class);
startActivityForResult(intent,20);
MainActivity.editClick++;
}
if(position==21){
Intent intent= new Intent(view.getContext(),Activity22.class);
startActivityForResult(intent,21);
MainActivity.editClick++;
}
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String query) {
// TODO Auto-generated method stub
adapter.getFilter().filter(query);
return false;
}
});
}
private ArrayList<ArrayListe> getPlayers()
{
ArrayList<ArrayListe> ArrayLister=new ArrayList<ArrayListe>();
ArrayListe p;
for(int i=0;i<names.length;i++)
{
p=new ArrayListe(names[i], images[i]);
ArrayLister.add(p);
}
return ArrayLister;
}
}
and the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGray"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorWhite">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="327dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:clickable="true"
app:cardBackgroundColor="@color/colorGray"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
tools:layout_editor_absoluteX="31dp"
tools:layout_editor_absoluteY="0dp">
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_alignRight="@+id/listView1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:iconifiedByDefault="false"
android:paddingLeft="-15dp"
android:queryHint="Søg..">
</SearchView>
</android.support.v7.widget.CardView>
</RelativeLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:background="@color/colorGray"
android:backgroundTint="@color/colorGray"
android:divider="@color/colorGray"
android:dividerHeight="5dp" />
</RelativeLayout
.................................................................... .. . . . . . . . . . . . . . . . . . .
android listview search searchview
When I search an event it works, but when I click on the event it gives me the wrong item on the ListView
even though it changed the ListView
.
What should I do to make it work ?
public class Searchable extends Activity {
ListView lv;
SearchView sv;
String names={"Gratis mad på Frederik Bajers vej 7","Gratis æbleskiver på basis","Growstack: Vertical Wednesday #5","Videoredigerings kursus","Kursus i Psykisk førstehjælp - modul 1","Nye øjne på jobsøgningen","Vr-turnering i CS samt racersimulator", "Nytårsfest med bowling og spisning- kom og tag kegler","Temamøde om patenter og immaterielle rettigheder i Aalborg","Stationsnær byfortætning- kan vi få det hele?", "Den Gode, den Onde og den Grundige kode", "Foredrag med Kurt Kragh - Kan du tænke som en morder?", "SAVEUS koncert","Varm jazz på en kold vinterdag", "Julekoncert med trompetisten Per Nielsen i Brødrenmenighedens Krike i Christiansfeld", "Hygge Friday 2nd edition","Filmaften: Fantastiske skabninger 2- Grindelwalds forbrydelser","Boblesmagning- find dine nytårsbobler", "Jan Gintberg: Hemmeligheden bag den gode ide","Netværk og uopfordret jobsøgning", "The Magic og Science","2nd Nordic-Italian Polymer Future workshop" };
int images={R.drawable.b1,R.drawable.b2,R.drawable.b3,R.drawable.b4,R.drawable.b5,R.drawable.b6,R.drawable.b7,R.drawable.b8,R.drawable.b9,R.drawable.b10,R.drawable.b11,R.drawable.b12,R.drawable.b13,R.drawable.b14,R.drawable.b15,R.drawable.b16,R.drawable.b17,R.drawable.b18,R.drawable.b19,R.drawable.b20,R.drawable.b21,R.drawable.b22};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.searchable);
lv=(ListView) findViewById(R.id.listView1);
sv=(SearchView) findViewById(R.id.searchView1);
//ADASPTER
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
if(position==0){
Intent intent= new Intent(view.getContext(),Activity1.class);
startActivityForResult(intent,0);
MainActivity.editClick++;
}
if(position==1){
Intent intent= new Intent(view.getContext(),Activity2.class);
startActivityForResult(intent,1);
MainActivity.editClick++;
}
if(position==2){
Intent intent= new Intent(view.getContext(),Activity3.class);
startActivityForResult(intent,2);
MainActivity.editClick++;
}
if(position==3){
Intent intent= new Intent(view.getContext(),Activity4.class);
startActivityForResult(intent,3);
MainActivity.editClick++;
}
if(position==4){
Intent intent= new Intent(view.getContext(),Activity5.class);
startActivityForResult(intent,4);
MainActivity.editClick++;
}
if(position==5){
Intent intent= new Intent(view.getContext(),Activity6.class);
startActivityForResult(intent,5);
MainActivity.editClick++;
}
if(position==6){
Intent intent= new Intent(view.getContext(),Activity7.class);
startActivityForResult(intent,6);
MainActivity.editClick++;
}
if(position==7){
Intent intent= new Intent(view.getContext(),Activity8.class);
startActivityForResult(intent,7);
MainActivity.editClick++;
}
if(position==8){
Intent intent= new Intent(view.getContext(),Activity9.class);
startActivityForResult(intent,8);
MainActivity.editClick++;
}
if(position==9){
Intent intent= new Intent(view.getContext(),Activity10.class);
startActivityForResult(intent,9);
MainActivity.editClick++;
}
if(position==10){
Intent intent= new Intent(view.getContext(),Activity11.class);
startActivityForResult(intent,10);
MainActivity.editClick++;
}
if(position==11){
Intent intent= new Intent(view.getContext(),Activity12.class);
startActivityForResult(intent,11);
MainActivity.editClick++;
}
if(position==12){
Intent intent= new Intent(view.getContext(),Activity13.class);
startActivityForResult(intent,12);
MainActivity.editClick++;
}
if(position==13){
Intent intent= new Intent(view.getContext(),Activity14.class);
startActivityForResult(intent,13);
MainActivity.editClick++;
}
if(position==14){
Intent intent= new Intent(view.getContext(),Activity15.class);
startActivityForResult(intent,14);
MainActivity.editClick++;
}
if(position==15){
Intent intent= new Intent(view.getContext(),Activity16.class);
startActivityForResult(intent,15);
MainActivity.editClick++;
}
if(position==16){
Intent intent= new Intent(view.getContext(),Activity17.class);
startActivityForResult(intent,16);
MainActivity.editClick++;
}
if(position==17){
Intent intent= new Intent(view.getContext(),Activity18.class);
startActivityForResult(intent,17);
MainActivity.editClick++;
}
if(position==18){
Intent intent= new Intent(view.getContext(),Activity19.class);
startActivityForResult(intent,18);
MainActivity.editClick++;
}
if(position==19){
Intent intent= new Intent(view.getContext(),Activity20.class);
startActivityForResult(intent,19);
MainActivity.editClick++;
}
if(position==20){
Intent intent= new Intent(view.getContext(),Activity21.class);
startActivityForResult(intent,20);
MainActivity.editClick++;
}
if(position==21){
Intent intent= new Intent(view.getContext(),Activity22.class);
startActivityForResult(intent,21);
MainActivity.editClick++;
}
}
});
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String arg0) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean onQueryTextChange(String query) {
// TODO Auto-generated method stub
adapter.getFilter().filter(query);
return false;
}
});
}
private ArrayList<ArrayListe> getPlayers()
{
ArrayList<ArrayListe> ArrayLister=new ArrayList<ArrayListe>();
ArrayListe p;
for(int i=0;i<names.length;i++)
{
p=new ArrayListe(names[i], images[i]);
ArrayLister.add(p);
}
return ArrayLister;
}
}
and the layout.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorGray"
tools:context=".MainActivity">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="@color/colorWhite">
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="327dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:clickable="true"
app:cardBackgroundColor="@color/colorGray"
app:cardCornerRadius="10dp"
app:cardUseCompatPadding="true"
tools:layout_editor_absoluteX="31dp"
tools:layout_editor_absoluteY="0dp">
<SearchView
android:id="@+id/searchView1"
android:layout_width="wrap_content"
android:layout_height="32dp"
android:layout_alignRight="@+id/listView1"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:clickable="true"
android:iconifiedByDefault="false"
android:paddingLeft="-15dp"
android:queryHint="Søg..">
</SearchView>
</android.support.v7.widget.CardView>
</RelativeLayout>
<ListView
android:id="@+id/listView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="60dp"
android:background="@color/colorGray"
android:backgroundTint="@color/colorGray"
android:divider="@color/colorGray"
android:dividerHeight="5dp" />
</RelativeLayout
.................................................................... .. . . . . . . . . . . . . . . . . . .
android listview search searchview
android listview search searchview
edited Nov 20 '18 at 14:37
barbsan
2,35821222
2,35821222
asked Nov 20 '18 at 11:22
Jacob ChristensenJacob Christensen
1
1
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
1
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31
add a comment |
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
1
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
1
1
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31
add a comment |
1 Answer
1
active
oldest
votes
Problem sovled.
With code:
In arraylist.
@Override
public String toString() {
return name;
}
}
In my Searchable:
added this line.
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//ArrayListe item= (ArrayListe) Adapter.getItem(position);
String name = lv.getItemAtPosition(position).toString();
for (int index = 0; index < names.length; index++){
if (name.equals(names[index])) {
position = index;
break;
}
}
if(position==0){
startActivity(new Intent(view.getContext(), Activity1.class));
MainActivity.editClick++;
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391929%2fsearching-listview-with-showing-wrong-items%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
Problem sovled.
With code:
In arraylist.
@Override
public String toString() {
return name;
}
}
In my Searchable:
added this line.
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//ArrayListe item= (ArrayListe) Adapter.getItem(position);
String name = lv.getItemAtPosition(position).toString();
for (int index = 0; index < names.length; index++){
if (name.equals(names[index])) {
position = index;
break;
}
}
if(position==0){
startActivity(new Intent(view.getContext(), Activity1.class));
MainActivity.editClick++;
}
add a comment |
Problem sovled.
With code:
In arraylist.
@Override
public String toString() {
return name;
}
}
In my Searchable:
added this line.
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//ArrayListe item= (ArrayListe) Adapter.getItem(position);
String name = lv.getItemAtPosition(position).toString();
for (int index = 0; index < names.length; index++){
if (name.equals(names[index])) {
position = index;
break;
}
}
if(position==0){
startActivity(new Intent(view.getContext(), Activity1.class));
MainActivity.editClick++;
}
add a comment |
Problem sovled.
With code:
In arraylist.
@Override
public String toString() {
return name;
}
}
In my Searchable:
added this line.
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//ArrayListe item= (ArrayListe) Adapter.getItem(position);
String name = lv.getItemAtPosition(position).toString();
for (int index = 0; index < names.length; index++){
if (name.equals(names[index])) {
position = index;
break;
}
}
if(position==0){
startActivity(new Intent(view.getContext(), Activity1.class));
MainActivity.editClick++;
}
Problem sovled.
With code:
In arraylist.
@Override
public String toString() {
return name;
}
}
In my Searchable:
added this line.
final Adapter adapter=new Adapter(this, getPlayers());
lv.setAdapter(adapter);
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//ArrayListe item= (ArrayListe) Adapter.getItem(position);
String name = lv.getItemAtPosition(position).toString();
for (int index = 0; index < names.length; index++){
if (name.equals(names[index])) {
position = index;
break;
}
}
if(position==0){
startActivity(new Intent(view.getContext(), Activity1.class));
MainActivity.editClick++;
}
answered Nov 20 '18 at 13:00
Jacob ChristensenJacob Christensen
1
1
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53391929%2fsearching-listview-with-showing-wrong-items%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
please try and cut the code to the absolut minimum you need, to reproduce the error.
– Jere
Nov 20 '18 at 12:03
I am kinda confused on what you mean ?
– Jacob Christensen
Nov 20 '18 at 12:28
1
remove as much of the code as you can where you still have the same problem. That saves us all a lot of time reading unnecessary code lines and also, it makes your question more useful to other users in the future.
– Jere
Nov 20 '18 at 12:31