그래서 스크롤보기 내에 표보기가있는 활동이 있습니다. 동적으로 표보기에 행을 추가합니다. 각 행에는 2 개의 스팅과 2 개의 정수가 데이터베이스에서 쿼리됩니다. 전체 행을 삭제하는 행에 단추를 추가하고 해당 행이 포함 된 데이터베이스에서 데이터를 삭제해야합니다.Android 삭제 버튼
버튼을 설정했지만 onClickListner에 쓰지 못했습니다. 어떤 버튼을 누르는 지 감지하는 방법과 해당 버튼을 해당 행과 연관시키는 방법을 알지 못합니다.
도움을 주시면 감사하겠습니다. 감사 !
이것은 행을 추가하는 방법입니다. Location 객체는 DB에서 가져온 데이터 만 보유합니다.
public void insertRow(Location l,int index){
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View newRow = inflater.inflate(R.layout.row, null);
TextView textview = (TextView) newRow.findViewById(R.id.textViewLocation);
TextView textview2= (TextView) newRow.findViewById(R.id.coordinates);
textview2.setText(l.getLatitude() +" | "+ l.getLongitude());
textview.setText(l.getName());
//Button remove = (Button) newRow.findViewById(R.id.removeButtonLocation);
// remove.setOnClickListener(removeLocationListener);
// Add the new components for the location to the TableLayout
a.addView(newRow, index);
}
그리고 레이아웃 파일
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="@+id/locations_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/row0"
android:layout_gravity="center" />
<ScrollView
android:id="@+id/Locations_scroll_view"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TableLayout
android:id="@+id/stockTableScrollView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/egg_shell" >
</TableLayout>
</ScrollView>
</LinearLayout>
시도한 것에 대해 몇 가지 코드를 추가하면 도움이됩니다. 그렇게하십시오, 그것은 또한 당신이 무엇을하려고하는지 명확하게 할 것입니다 :) –
나는 활동이 너무 많습니다, 그는 지금 집에 있습니다. 젠장. –
코드를 작성하고 추가했습니다. –