1
나는 ListView
이고 그 안에는 ListView
입니다. ImageButton
입니다. 사용자가 ImageButton을 클릭하면 새 항목이 팽창하지만 새 항목을 추가 할 때마다 아래로 스크롤하여 추가 된 항목을 확인해야합니다. 나는 그 스크롤이 추가 된 후 자동으로 마지막 항목으로 이동하도록 도움을 필요로한다.베이스 어댑터에서 목록보기의 맨 아래로 스크롤
내 ImageButton
은 다른 레이아웃이지만 (목록 뷰의 일부 임) 동일한 레이아웃에는 풍선 뷰의 부모보기로 사용되는 LinearLayout
이 있습니다.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/relativeLayoutOther"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/_5sdp">
<TextView
android:id="@+id/objectiveOtherCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Add Other Objectives"
android:layout_marginStart="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
android:textColor="@color/common_google_signin_btn_text_light_focused"
android:textSize="@dimen/_12ssp" />
<ImageButton
android:id="@+id/addOtherObjectiveTextBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/objectiveOtherCheckBox"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_marginTop="@dimen/_10sdp"
android:background="@drawable/round_button2"
android:src="@android:drawable/ic_input_add"/>
//parent layout
<LinearLayout
android:id="@+id/otherObjLinearLayout"
android:layout_width="wrap_content"
android:layout_marginTop="@dimen/_15sdp"
android:layout_marginLeft="@dimen/_10sdp"
android:layout_below="@+id/objectiveOtherCheckBox"
android:layout_height="wrap_content"
android:orientation="vertical"/>
</RelativeLayout>
이 아이 뷰를 팽창 내 기본 어댑터 내부의 코드는 다음과 같습니다
이
내 XML이다. 이 함수에서는 항목을 추가 한 후ListView
을 맨 아래로 스크롤하려고합니다.
ImageButton imageButton = (ImageButton) convertView.findViewById(R.id.addOtherObjectiveTextBox);
imageButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
//Toast.makeText(v.getContext(), "Clicked123", Toast.LENGTH_SHORT).show();
final Dialog dialog = new Dialog(v.getContext());
dialog.setContentView(R.layout.otherobjectivedialog);
final EditText enterObjET = (EditText) dialog.findViewById(R.id.enterObjEditText);
Button closeEnterObjBtn = (Button) dialog.findViewById(R.id.closeEnterObjDialog);
Button objConfirmBtn = (Button) dialog.findViewById(R.id.enterObjConfirmBtn);
closeEnterObjBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog.dismiss();
}
});
objConfirmBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(final View v) {
final String enteredObj = enterObjET.getText().toString();
if(enteredObj.equals("")){
Toast.makeText(v.getContext(), "Please write a objective", Toast.LENGTH_LONG).show();
}else {
final View editChildView = layoutInflater.inflate(R.layout.other_objective_edittext, null);
editParentLL.addView(editChildView);
final TextView tvOO = editChildView.findViewById(R.id.otherobjTextView);
ImageView ivOOEdit = editChildView.findViewById(R.id.otherobjEdit);
ImageView ivOODelete = editChildView.findViewById(R.id.otherobjDelete);
tvOO.setText(enteredObj);
ivOODelete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int posValue2 = editParentLL.indexOfChild(editChildView);
editParentLL.removeView(editChildView);
otherObjList.remove(posValue2);
}
});
ivOOEdit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int editPosValue = editParentLL.indexOfChild(editChildView);
final Dialog dialog2 = new Dialog(con);
dialog2.setContentView(R.layout.otherobjectivedialog);
final EditText enterObjET2 = (EditText) dialog2.findViewById(R.id.enterObjEditText);
Button closeEnterObjBtn2 = (Button) dialog2.findViewById(R.id.closeEnterObjDialog);
Button objConfirmBtn2 = (Button) dialog2.findViewById(R.id.enterObjConfirmBtn);
String otherObjectiveTextToEdit = otherObjList.get(editPosValue);
enterObjET2.setText(otherObjectiveTextToEdit);
closeEnterObjBtn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
dialog2.dismiss();
}
});
objConfirmBtn2.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
int editPosValue2 = editParentLL.indexOfChild(editChildView);
final String enteredObj2 = enterObjET2.getText().toString();
if(enteredObj2.equals("")){
Toast.makeText(con, "Please write a objective", Toast.LENGTH_LONG).show();
}else {
dialog2.dismiss();
tvOO.setText(enteredObj2);
otherObjList.put(editPosValue2, enteredObj2);
}
}
});
dialog2.show();
}
});
//objectiveOtherET.setText(objectiveOtherET.getText().toString()+ " \n" + enteredObj);
//Log.i("POS", "onClick: "+editParentLL.indexOfChild(editChildView));
otherObjList.put(oo, enteredObj);
oo++;
dialog.dismiss();
}
}
});
dialog.show();
/* LinearLayout linearLayoutNew = new LinearLayout(con);
linearLayoutNew.setOrientation(LinearLayout.VERTICAL);
et = new EditText(con);
LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
et.setLayoutParams(p);
et.setHint("Set some objective");
linearLayoutNew.addView(et);
ll.addView(linearLayoutNew);*/
}
어떻게베이스 어댑터에서 ListView에 액세스 할 수 있습니까? – 3iL
그 중 한가지 방법이 있습니다. 액티비티에 public 메소드를 생성하고 호출하십시오. – ADM
기본 어댑터의 목록 생성기에 listview를 전달한 다음 코드를 사용했지만 작동하지 않았습니다. – 3iL