Listviewを使用して講義を表示するアプリがあります。講義は、そのタイプによって色分けされています。カスタムアダプターを使用して、各講義のさまざまな色をコントロールしました。私は以下のコードを使用してアダプタを呼び出す -Listviewアダプタの問題
cursor = myDbHelper.getReadableDatabase().rawQuery(sql, null);
startManagingCursor(cursor);
adapter = new Lectures_Adapter(this,R.layout.menu_item,cursor,FROM,TO);
menuList.setAdapter(adapter);
私が講義を注文し直すまでは、すべての場所で言う、[OK]を動作します。私が使用するコードがある - 私のカスタムアダプタ(Lectures_Adapter)で
Cursor newCursor = myDbHelper.getReadableDatabase().rawQuery(sqlStr, null);
adapter.changeCursor(newCursor);
のコードは以下の通りですが、講義が再順序付けされたときに呼び出されません。
public class Lectures_Adapter extends SimpleCursorAdapter {
private Context appContext;
private int layout;
private Cursor mycursor;
public Lectures_Adapter(Context context, int layout, Cursor c, String[] from,int[] to) {
super(context, layout, c, from, to);
this.appContext=context;
this.layout=layout;
this.mycursor=c;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
View view = super.getView(position, convertView, parent);
try {
if (position > 0)
{
RelativeLayout rowFill = (RelativeLayout) convertView.findViewById(R.id.rowFill);
String title = mycursor.getString(1);
int myColor = 0;
int myPos = title.indexOf("Nursing");
int myPos2 = title.indexOf("Masterclass");
if (myPos >= 0)
{
myColor = Color.parseColor("#99FF66");
}
else if (myPos2 >= 0)
{
myColor = Color.parseColor("#FF99FF");
}
else
{
myColor = Color.parseColor("#FFFF66");
}
convertView.findViewById(R.id.rowFill).setBackgroundColor(myColor);
}
}catch(Exception e) {
}
if (convertView == null) {
LayoutInflater inflator = (LayoutInflater) this.appContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflator.inflate(this.layout,null);
} else {
convertView = (View) convertView;
}
return view;
}
}
誰かが私は動的に私のリストビューを注文し直すと、その都度、アダプタのカスタム私を呼び出すことができる方法を教えてくださいすることができます。
どのように再注文していますか?それはいくつかのクリックか? – kosa
私は、ユーザーにデータを注文する4つの方法のオプションを与えるダイアログボックスを持っています。それらが選択されると、上記のコードに新しいクエリを渡します(カーソルはmyDbHelper.getReadableDatabase()にあります)。rawQuery(sql、null);) – user616076