如何从每个被点击的字符串项中设置一个intent的类

时间:2013-01-06 16:16:31

标签: android android-intent

我正在尝试从点击的每个项目开始另一个意图 还请告诉我在哪里可以提供您的解决方案代码
这是代码

import java.util.ArrayList;
import java.util.HashMap;
import android.app.ListActivity;
import android.app.Activity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.widget.ArrayAdapter;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.EditText;
import android.widget.ListView;
import android.view.View.OnClickListener;
public class MainActivity extends Activity {

// List view
private ListView lv;

// Listview Adapter
ArrayAdapter<String> adapter;

// Search EditText
EditText inputSearch;

// ArrayList for Listview
ArrayList<HashMap<String, String>> productList;

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    // Listview Data
    String products[] = {"Dell", "HTC ","iPhone ", "Samsung Galaxy"};

    lv = (ListView) findViewById(R.id.list_view);
    inputSearch = (EditText) findViewById(R.id.inputSearch);

    // Adding items to listview
    adapter = new ArrayAdapter<String>(this, R.layout.list_item, R.id.product_name,products);
    lv.setAdapter(adapter);

    /**
     * Enabling Search Filter
     * */
    inputSearch.addTextChangedListener(new TextWatcher() {

         @Override
     public void onTextChanged(CharSequence cs, int arg1, int arg2, int arg3) {
         // When user changed the Text
         Identifikasi1.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
     }

 });
 }

我还是初学者,不知道要解决这个问题

1 个答案:

答案 0 :(得分:0)

您应该实现onItemClickListener并在侦听器方法onItemClick()中设置意图 例如:

public void MainActivity extends Activity implements onItemClickListener{
   //your code
  //...

@Override public void onItemClick(AdapterView parent, View view, int position,long id) { Intent intent = new Intent(); } }