Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class MainMenu extends AppCompatActivity {
- ListView listView;
- EditText editTextView;
- ArrayList<Lesson> ItemModelList;
- CustomAdapter customAdapter;
- Button BLogout;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_mainmenu);
- final TextView welcomeMessage = (TextView) findViewById(R.id.tvWelcome);
- final Button BLogout = (Button) findViewById(R.id.BLogout);
- Intent intent = getIntent();
- String username = intent.getStringExtra("username");
- String message = username + " Welcome";
- welcomeMessage.setText(message);
- BLogout.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View view) {
- Intent registerIntent = new Intent(MainMenu.this, Login.class);
- MainMenu.this.startActivity(registerIntent);
- }
- });
- listView = (ListView) findViewById(R.id.listview);
- editTextView = (EditText) findViewById(R.id.editTextView);
- ItemModelList = new ArrayList<Lesson>();
- customAdapter = new CustomAdapter(getApplicationContext(), ItemModelList);
- listView.setEmptyView(findViewById(R.id.empty));
- listView.setAdapter(customAdapter);
- }
- @SuppressLint("NewApi")
- public void addValue(View v) {
- String name = editTextView.getText().toString();
- if (name.isEmpty()) {
- Toast.makeText(getApplicationContext(), "Plz enter Values",
- Toast.LENGTH_SHORT).show();
- } else {
- Lesson md = new Lesson(name);
- ItemModelList.add(md);
- customAdapter.notifyDataSetChanged();
- editTextView.setText("");
- }
- }}
- ublic class CustomAdapter extends BaseAdapter {
- Context context;
- ArrayList<Lesson> itemLessonList;
- public CustomAdapter(Context context, ArrayList<Lesson> lessonList) {
- this.context = context;
- this.itemLessonList = lessonList;
- }
- @Override
- public int getCount() {
- return itemLessonList.size();
- }
- @Override
- public Object getItem(int position) {
- return itemLessonList.get(position);
- }
- @Override
- public long getItemId(int position) {
- return position;
- }
- @Override
- public View getView(final int position, View convertView, ViewGroup parent) {
- convertView = null;
- if (convertView == null) {
- LayoutInflater mInflater = (LayoutInflater) context
- .getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
- convertView = mInflater.inflate(R.layout.item, null);
- TextView tvName = (TextView) convertView.findViewById(R.id.tvName);
- ImageView imgRemove = (ImageView) convertView.findViewById(R.id.BDelete);
- Lesson m = itemLessonList.get(position);
- tvName.setText(m.getName());
- // click listener for remove button
- imgRemove.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- itemLessonList.remove(position);
- notifyDataSetChanged();
- }
- });
- }
- return convertView;
- }}
- public class Lesson {
- String name;
- public Lesson(String name) {
- this.name = name;
- }
- public String getName() {
- return name;
- }}
- <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:background="@drawable/gradient">
- <TextView
- android:id="@+id/textView"
- android:layout_width="wrap_content"
- android:layout_height="35dp"
- android:layout_alignParentStart="true"
- android:layout_alignParentTop="true"
- android:gravity="left"
- android:text="Lesson Board"
- android:textColor="@android:color/holo_blue_dark"
- android:textSize="27sp" />
- <Button
- android:id="@+id/BLogout"
- android:layout_width="wrap_content"
- android:layout_height="35dp"
- android:layout_alignParentEnd="true"
- android:layout_alignParentTop="true"
- android:text="Logout"
- android:background="@android:color/holo_blue_dark"/>
- <TextView
- android:id="@+id/tvWelcome"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:layout_below="@+id/textView"
- android:layout_centerHorizontal="true"
- android:layout_marginTop="22dp"
- android:text="hello world"
- android:textColor="@android:color/holo_blue_dark"
- android:textAppearance="?android:attr/textAppearanceLarge" />
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_alignParentEnd="true"
- android:layout_below="@+id/tvWelcome"
- android:orientation="vertical">
- <LinearLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:orientation="horizontal" >
- <EditText
- android:id="@+id/editTextView"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:hint="Add lesson"
- android:textColor="@android:color/holo_blue_dark"
- />
- <ImageView
- android:id="@+id/imgViewAdd"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:onClick="addValue"
- android:background="@android:drawable/ic_input_add"
- />
- </LinearLayout>
- <ListView
- android:id="@+id/listview"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:layout_weight="1"
- android:dividerHeight="2dp"
- android:textColor="@android:color/holo_blue_dark">
- </ListView>
- </LinearLayout>
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="horizontal" >
- <TextView
- android:id="@+id/tvName"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:layout_weight="1"
- android:gravity="left"
- android:padding="8dp"
- android:textColor="#000000"
- android:textSize="18sp" />
- <ImageView
- android:id="@+id/BDelete"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content"
- android:focusable="false"
- android:background="@android:drawable/ic_delete" />
Add Comment
Please, Sign In to add comment