我有一个MainActivity,CustomListAdapter,customlistItem.xml,mainlayout.xml,SwipeDismissListViewTouchListener.java,SwipeDismissTouchListener.java。
我正在使用this代码(轻扫以解除)。
我想在ListView&中创建一个可聚焦(可编辑)的EditText。 onItemClickListener ListView&滑动以关闭ListView。
我的代码在ListView和&amp ;;中可以很好地聚焦(可编辑)EditText。 onItemClickListener ListView。
但是无法使用Swipe to Dismiss ListView。
如果我创建一个新项目,那么滑动到Dismiss ListView效果很好,但是在ListView&中没有工作可聚焦(可编辑)EditText。 onItemClickListener ListView。
我认为TouchListener代码存在问题。(dupplicated)
我应该做什么?
MainActivity.java
...
footer.setOnClickListener(new View.onclickListener()
{
@Override
public void onClick(View v)
{
int id=0;
String list = "new";
String contents = "";
myHelper = new myDBHelper(myListActivity.this);
myadapter = new subMyListAdapter(myListActivity.this, R.layout.custom_edit_item, arrItem,myHelper);
mainList.setItemsCanFocus(false);
mainList.setAdapter(myadapter);
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(mainList,
new SwipeDismissListViewTouchListener.DismissCallbacks()
{
@Override
public boolean canDismiss(int position)
{
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions)
{
for (int position : reverseSortedPositions)
{
myadapter.remove(position);
}
myadapter.notifyDataSetChanged();
}
});
mainList.setOnTouchListener(touchListener);
mainList.setOnScrollListener(touchListener.makeScrollListener());
sqlDB = myHelper.getReadableDatabase();
Cursor cursor;
cursor = sqlDB.rawQuery("SELECT * FROM clearTBL;", null);
sqlDB.execSQL("INSERT INTO clearTBL(list, contents) VALUES ('"
+ list + "' , '" + "');");
arrItem.clear();
while (cursor.moveToNext())
{
id = cursor.getInt(0);
list = cursor.getString(1);
contents = cursor.getString(2);
subMyItem item = new subMyItem(id, list, contents);
arrItem.add(item);
}
myadapter.notifyDataSetChanged();
}
});
mainList.addFooterView(footerViewLayout, null, true);
mainList.setAdapter(myadapter);
mainList.setDivider(null);
SwipeDismissListViewTouchListener touchListener =
new SwipeDismissListViewTouchListener(mainList,
new SwipeDismissListViewTouchListener.DismissCallbacks()
{
@Override
public boolean canDismiss(int position)
{
return true;
}
@Override
public void onDismiss(ListView listView, int[] reverseSortedPositions)
{
for (int position : reverseSortedPositions)
{
myadapter.remove(position);
}
myadapter.notifyDataSetChanged();
}
});
subMyListAdapter.java
...
holder.tvItem.setOnTouchListener(test);
conv.setOnTouchListener(test);
...
View.OnTouchListener test= new View.OnTouchListener()
{
@Override
public boolean onTouch(View view, MotionEvent event)
{
if (view instanceof EditText)
{
tvItem = (EditText) view;
tvItem.setFocusable(true);
tvItem.setFocusableInTouchMode(true);
try
{
openPositon = Integer.parseInt(tvItem.getTag().toString());
}
catch(Exception e)
{}
if(sPosition!=null)
{
int pos = Integer.parseInt(sPosition);
myHelper = new myDBHelper(context);
SQLiteDatabase sqlDB = myHelper.getWritableDatabase();
subMyItem user = arraySrc.get(pos);
int a = user.id;
String update = "UPDATE clearTBL SET list='" + tvItem.getText().toString()+ "' WHERE id=" + a + ";";
try
{
sqlDB.execSQL(update);
}
catch (Exception e)
{
e.printStackTrace();
}
sqlDB.close();
myListActivity.arrItem.get(pos).list = tvItem.toString();
}
} else
{
hideSoftKeyboard();
view.requestFocus();
UserHolder holder = (UserHolder) view.getTag();
holder.tvItem.clearFocus();
holder.tvItem.setMovementMethod(null);
holder.tvItem.setFocusable(false);
holder.tvItem.setFocusableInTouchMode(false);
try
{
sPosition = tvItem.getTag().toString();
}
catch
(Exception e)
{}
if(sPosition!=null)
{
int pos = Integer.parseInt(sPosition);
myHelper = new myDBHelper(context);
SQLiteDatabase sqlDB = myHelper.getWritableDatabase();
subMyItem user = arraySrc.get(pos);
int a = user.id;
String update = "UPDATE clearTBL SET list='" + tvItem.getText().toString()+ "' WHERE id=" + a + ";";
try
{
sqlDB.execSQL(update);
}
catch (Exception e)
{
e.printStackTrace();
}
sqlDB.close();
myListActivity.arrItem.get(pos).list = tvItem.toString();
}
}
return false;
}
};
清单
...
android:windowSoftInputMode="adjustPan"
/*android:windowSoftInputMode="adjustResize" didn't works for Focusable EditText*/
...