Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?xml version="1.0" encoding="utf-8"?>
- <android.support.v4.widget.DrawerLayout
- xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/drawerLayout">
- <FrameLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:id="@+id/contentContainer">
- <TextView
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="content txt"
- android:layout_gravity="center"
- android:textSize="30sp"
- android:id="@+id/contentTxt"/>
- <Button
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:text="xXx"
- android:id="@+id/btn"/>
- </FrameLayout >
- <ListView
- android:layout_width="240dp"
- android:layout_height="match_parent"
- android:id="@+id/drawerList"/>
- </android.support.v4.widget.DrawerLayout>
- ////////////////////////////////////////////////////////////////////////////////////////////////////////////////
- import android.support.v4.widget.DrawerLayout;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.*;
- import java.util.ArrayList;
- import java.util.HashMap;
- import java.util.List;
- public class MainActivity extends AppCompatActivity {
- ListView drawerList;
- DrawerLayout drawerLayout;
- TextView contentTxt;
- private class ItemClickListener implements AdapterView.OnItemClickListener {
- @Override
- public void onItemClick(AdapterView<?> parent,View view,int position,long id) {
- StringBuilder sb= new StringBuilder();
- TextView label= (TextView)view.findViewById(R.id.label);
- TextView n= (TextView)view.findViewById(R.id.n);
- sb.append(label.getText() +"\t"+ n.getText() );
- contentTxt.setText(sb.toString() );
- }
- }
- private class Listener implements View.OnClickListener {
- @Override
- public void onClick(View v) {}
- }
- private void initAdapter() {
- String from[]= {"Label","n"};
- int to[]= {R.id.label,R.id.n};
- String strs[]= {"Молоко", "Сметана", "Хлеб", "Пылесос"};
- String ns[]= {"1", "2", "2", "0"};
- List<HashMap<String,Object> > data= new ArrayList<>();
- for(int i=0; i<strs.length; i++) {
- HashMap<String,Object> map= new HashMap();
- map.put(from[0],strs[i] );
- map.put(from[1],ns[i] );
- }
- SimpleAdapter adapter= new SimpleAdapter(this,data,R.layout.drawer_list_element,from,to);
- drawerList.setAdapter(adapter);
- }
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main_layout);
- Button btn= (Button)findViewById(R.id.btn);
- contentTxt= (TextView)findViewById(R.id.contentTxt);
- drawerList= (ListView)findViewById(R.id.drawerList);
- drawerLayout= (DrawerLayout)findViewById(R.id.drawerLayout);
- initAdapter();
- drawerList.setOnItemClickListener(new ItemClickListener());
- btn.setOnClickListener(new Listener() );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement