在使用搜索框时,如何在ListView上使用意图



我对我的代码有问题,并且仍然对每个项目的布局(如产品(具有自己的描述感到困惑有人知道如何解决我的问题吗?谢谢你

这是我的main_activity代码

import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.EditText;
import android.widget.ListView;
import java.util.ArrayList;
import static com.example.vinznolimit.herbindonesia.R.id.theList;
public class MainActivity extends AppCompatActivity {
    private static final String TAG = "MainActivity";
    private ArrayAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        ListView list= (ListView) findViewById(theList);
        EditText theFilter = (EditText) findViewById(R.id.searchFilter);
        Log.d(TAG, "onCreate: Started.");
        ArrayList<String> names = new ArrayList<>();
        names.add("Mitch");
        names.add("Blake");
        names.add("Blade");
        names.add("Bruno");
        names.add("Joe");
        names.add("Barry");
        adapter = new ArrayAdapter(this,R.layout.list_item,names);
        list.setAdapter(adapter);

theFilter.addTextChangedListener(new TextWatcher() {
            @Override
            public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            }
            @Override
            public void onTextChanged(CharSequence s, int start, int before, int count) {
                (MainActivity.this).adapter.getFilter().filter(s);
            }
            @Override
            public void afterTextChanged(Editable s) {
            }
        });

    }
}

尝试这个

list.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View v,
        int position, long id) {
        Intent myIntent = new Intent(v.getContext(), UserSubmissionLog.class);
        startActivity(myIntent);
        }
    }
);

最新更新