Zubayr Shah
Zubayr Shah

Reputation: 21

Listview Onitemclick nothing happen

this is my code

public class VorherbestimmungenActivity extends Activity {
private ListView lv1;
ArrayAdapter<String> adapter;
EditText inputSearch;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    ThemeUtils.onActivityCreateSetTheme(this);
    setContentView(R.layout.vorherbestimmung);

String products[] = getResources().getStringArray(R.array.vorherbestimmung);
    lv1 = (ListView) findViewById(R.id.listView1);
    inputSearch = (EditText) findViewById(R.id.inputSearch);
    adapter = new ArrayAdapter < String > (this, R.layout.list_item, R.id.product_name, products);

    lv1.setAdapter(adapter);
    inputSearch.addTextChangedListener(new TextWatcher() {
        @Override
        public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
            // When user changed the Text
            VorherbestimmungenActivity.this.adapter.getFilter().filter(cs);
        }

        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub
        }

        @Override
        public void afterTextChanged(Editable arg0) {
            // TODO Auto-generated method stub


    lv1.setOnItemClickListener(new OnItemClickListener() { @Override
        public void onItemClick(AdapterView<?> arg0, View view,
                  int position, long arg3) {

            if (position == 0) {
                Intent shareIntent = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent.setType("text/plain");
                String shareMessage = "This is Item1";
                shareIntent.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage);
                startActivity(Intent.createChooser(shareIntent, "Entscheiden Sie �ber was Sie teilen m�chten:"));
            } else if (position == 1) {
                Intent shareIntent1 = new Intent(android.content.Intent.ACTION_SEND);
                shareIntent1.setType("text/plain");
                String shareMessage1 = "This is Item2";
                shareIntent1.putExtra(android.content.Intent.EXTRA_TEXT,shareMessage1);
                startActivity(Intent.createChooser(shareIntent1, "Entscheiden Sie �ber was Sie teilen m�chten:"));
            }
                        }

            });
        }
    });
}

}

So my Problem is, that if i click on the item nothing happen. They dont share the message. If i change the name.equals to position it is work but they Show me the wrong share text. And it only work if i search the item.

Thx for your Help.

Upvotes: 1

Views: 149

Answers (2)

Mateus Brandao
Mateus Brandao

Reputation: 900

Remove the code:

@Override 
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2, long arg3) {
    // TODO Auto-generated method stub 

} 

and add @Override to your public void onItemClick().

Upvotes: 1

MilanNz
MilanNz

Reputation: 1341

Change :

String name = adapter.getItem(position);

with:

String name = (String)arg0.getItemAtPosition(position);

Upvotes: 1

Related Questions