大家好我有一個問題,就是在列表視圖中刪除或隱藏列表,像javascript中的.hide()。我知道這裏有很多答案,但它似乎沒有回答我的問題。爲了清楚解釋,下面是我的代碼的一部分。刪除或隱藏列表視圖中的一行
package sample.wew.wew;
import info.androidhive.sqlite.model.Message;
import java.util.ArrayList;
import java.util.List;
import android.content.Intent;
import android.database.Cursor;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListAdapter;
import android.widget.ListView;
import android.widget.SimpleCursorAdapter;
import android.widget.TextView;
import android.widget.Toast;
import android.widget.AdapterView.OnItemClickListener;
public class QuestionsSent extends Fragment {
private static final String TAG = "Question";
private static List questions;
protected ListAdapter adapter;
ListView theList;
@SuppressWarnings("deprecation")
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view;
view = inflater.inflate(R.layout.questions_main_layout, container, false);
AskdDatabaseHelper msg_db = new AskdDatabaseHelper(getActivity());
Cursor cursor = msg_db.FetchQuestion("S");
String[] fromFieldNames = new String[] { "msg_from_user", "msg_message" };
int[] toViewIDs = new int[] { R.id.tvMessage, R.id.tvMessageSender };
adapter = new QuestionsCursorAdapter(getActivity(), // Context
R.layout.question_detail, // Row layout template
cursor, // cursor (set of DB records to map)
fromFieldNames, // DB Column names
toViewIDs // View IDs to put information in
);
theList = (ListView) view.findViewById(R.id.list);
theList.setAdapter(adapter);
theList.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
/*
Log.v(TAG, ": NAAY GI CLICK");
Intent intent = new Intent(getActivity(), Sent_details.class);
Cursor cursor = (Cursor) adapter.getItem(position);
Log.d("TAG", "" + adapter.getItem(position));
intent.putExtra("MESSAGE_ID", cursor.getString(cursor.getColumnIndex("msg_message")));
startActivity(intent);
*/
// HERE IS WHERE I WANT TO PUT MY CODE TO DELETE OR HIDE A LIST
}
});
if(adapter.isEmpty()){
view = inflater.inflate(R.layout.fragments_question_new, container, false);
((TextView)view.findViewById(R.id.textView)).setText("No Sent Questions");
}
return view;
}
}
要刪除從隨機行/記錄列表?我對嗎? – Umair 2014-08-28 09:12:48
@Darkie我想刪除我點擊過的那一行。 – Hope 2014-08-28 09:14:35
所以我假設你在數據庫的listview中顯示記錄? – Umair 2014-08-28 09:15:59