开发者

Edit option in Android tableLayout like in iphone UITableView

I need to have an edit option in tableLayout just like in iphone UITableView. When edit button is clicked a Delete button should appear in each row of tableLayout. What I just did was I created a Delete button in each row at runtime and made it hide. And when Edit button is clicked, Delete button gets visible. But I don't think it seems to be a good practice.

Is there an inbuilt functionality for this? What is t开发者_如何学Che best practice I should follow?

Thanks and regards


You can always make a seperate xml file containing only a delete button and then inflate it into all the rows when the edit button is clicked.That way you dont have to hide all those delete buttons and can add them only if needed...

Create a new xml file under res->layout and add only this to it

<Button
xmlns:android="http://schemas.android.com/apk/res/android"
   android:id="@+id/delete"
   android:layout_width="20sp"
   android:layout_height="20sp"
   android:padding="10sp">
  </Button> 

Then just inflate it into your row.

//create inflater
LayoutInflater inflater = getLayoutInflater();

//inflate delete button.
//You can put this in a loop to have a delete button in all your rows.     
View delete_button = inflater.inflate(R.layout.YOURROWID,
            (ViewGroup) YOURROWNAME, false);

For more info this is a good tutorial to understand inflation- http://blog.jayway.com/2009/03/26/layout-resources-in-android/ Good luck! :)


Try using ContextMenus. Long press on any row should give u a pop-up screen to delete that row. Implement onContextItemSelected to delete

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜