将Activity放入Tablayout

时间:2017-05-05 11:43:14

标签: android android-fragments android-tablayout

我有一些适配器的这个活动,我会把它放在tableLayout我已经尝试了一些方法,

不幸的是他们没有工作,(使用onCreateView()扩展FragmentActivity,将活动转换为片段)

`public class MainActivity_Delete extends AppCompatActivity` {

private SwipeMenuListView listView;
private ArrayList<Data> dataArrayList;
private ListAdapter listAdapter;
private Data data;
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_delete);

    listView = (SwipeMenuListView) findViewById(R.id.listview);
    dataArrayList = new ArrayList<>();
    listAdapter = new ListAdapter(this, dataArrayList);
    listView.setAdapter(listAdapter);

    listView.setMenuCreator(creator);

    listView.setOnMenuItemClickListener(new SwipeMenuListView.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(int position, SwipeMenu menu, int index) {
            switch (index) {
                case 0:

                    Toast.makeText(MainActivity_Delete.this, "Delete", Toast.LENGTH_SHORT).show();
                    Log.e("item", String.valueOf(listView.getAdapter().getItem(position)));
                    Log.e("name", String.valueOf(dataArrayList.get(position).getName()));

                    dataArrayList.remove(position);

                    listAdapter.notifyDataSetChanged();

                    break;
                case 1:
                    // delete
                    break;
            }
            // false : close the menu; true : not close the menu
            return false;
        }
    });

}

SwipeMenuCreator creator = new SwipeMenuCreator() {
    @Override
    public void create(SwipeMenu menu) {


        // create "delete" item
        SwipeMenuItem deleteItem = new SwipeMenuItem(
                getApplicationContext());
        // set item background
        deleteItem.setBackground(new ColorDrawable(Color.parseColor("#F45557")));
        // set item width
        deleteItem.setWidth(150);

        deleteItem.setTitle("Delete");
        deleteItem.setTitleColor(Color.WHITE);
        deleteItem.setTitleSize(15);

        // add to menu
        menu.addMenuItem(deleteItem);
    }
};

}

1 个答案:

答案 0 :(得分:0)

android.app.ActivityGroup但是这个类自API级别13以来已被弃用。因此,实质上您无法在另一个活动中嵌入活动。但是,您可以重用布局文件。见Re-using Layouts with <include/>当然,最好的选择是使用片段。它们是这类事物的标准。