0

我有一个列表视图,基本上,如果用户尚未单击该位置,我希望Listview填充并显示“新建”,然后在用户单击该项目后将可见性设置为消失。谁能帮助我?TextViewTextViewListview

我已经尝试了相当多的一些代码,当然通过反复试验,擦除代码,所以我无法向您展示我尝试过的所有内容。这是我尝试的最后一件事:

        // selecting single ListView item
    final ListView lv = getListView();



    // Launching new screen on Selecting Single ListItem
    lv.setOnItemClickListener(new OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view,
                int position, long ide) {

            if (lv.isPressed(view.hasFocus(position))) { 
                newjob.setVisibility(View.VISIBLE); 
            } else { 
                newjob.setVisibility(View.GONE); 
            } 


               vib.vibrate(40); 

                // Starting new intent 
                try { 
                Intent in = new Intent(getApplicationContext(), 
                        SingleMenuItemActivity.class); 
                in.putExtra("jobInfo", JOBS.getJSONObject(position).toString()); 
                in.putExtra(pays, JOBS.getJSONObject(position).toString());
                in.putExtra(job, JOBS.getJSONObject(position).toString());
                in.putExtra(ready_at, JOBS.getJSONObject(position).toString());
                in.putExtra(due_by, JOBS.getJSONObject(position).toString());
                in.putExtra(customer_reference, JOBS.getJSONObject(position).toString());
4

1 回答 1

1

这是一种方法,只需覆盖OnItemClickListener

lv.setOnItemClickListener(new OnItemClickListener() {
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        // Change your TextView's visibility to gone
        view.findViewById(R.id.textView).setVisibility(View.GONE);
    }
});

从新代码更新

看起来您正在使用 ListActivity 或 ListFragment。如果是这样,我建议使用 onListItemClick() 而不是 onItemClick() 因为它已经设置:

@Override
protected void onListItemClick (ListView listView, View view, int position, long id) {
    view.findViewById(R.id.textView).setVisibility(View.GONE);
}
于 2012-08-10T22:30:14.690 回答