Text Visible in other Activities, - android

i just needed some quick help. I got a nav drawer setup, and i use activity main as my welcome screen, so I put a text box on the activity_main, but the problem is that when I chose other nav drawer pages, i see the text box from the activity main.
What one of my activity pages should look like: http://puu.sh/nQFkc/1ed83811cc.png
What it ends up looking like: http://puu.sh/nQF93/785c9eee45.png
Need to mention im new to android?
Main Activity
package nota.outlawsindex;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
Toolbar toolbar;
Scrollview scrollView;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
setupToolbar();
DataModel[] drawerItem = new DataModel[4];//need to update this if you add start counting at 0
drawerItem[0] = new DataModel(R.drawable.ic_connect, "Calculate Sentence");
drawerItem[1] = new DataModel(R.drawable.ic_fixtures, "Felonies");
drawerItem[2] = new DataModel(R.drawable.ic_table, "Misdemeanors");
drawerItem[3] = new DataModel(R.drawable.ic_drawer, "Infractions");
//add on to the list to create more pages
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setupDrawerToggle();
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
scrollView.setVisibility(View.GONE);
Fragment fragment = null;
switch (position) {
case 0:
fragment = new ConnectFragment();
break;
case 1:
fragment = new FixturesFragment();
break;
case 2:
fragment = new TableFragment();
break;
case 3:
fragment = new SelfAddedFragment();
break;
//add more cases if you add more pages
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(mNavigationDrawerItemTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e("MainActivity", "Error in creating fragment");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//
int id = item.getItemId();
//
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
} else if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(), "Settings", Toast.LENGTH_SHORT).show();
return true;
}
Toast.makeText(getApplicationContext(), "Search", Toast.LENGTH_SHORT).show();
return super.onOptionsItemSelected(item);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
void setupToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//getSupportActionBar().setDisplayShowHomeEnabled(true);
}
void setupDrawerToggle() {
mDrawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
//This is necessary to change the icon of the Drawer Toggle upon state change.
mDrawerToggle.syncState();
}
}
Activity_Main
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundColor">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/relativeLayout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/container_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</FrameLayout>
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_gravity="right|top"
android:layout_below="#+id/scrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/content_frame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/relativeLayout2"
android:focusable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="? android:attr/textAppearanceSmall"
android:text=" Welcome to The Outlaw&apos;s Index! An app designed for individuals who want to educate themselves with knowledge regarding different types of offenses in the United States. Currently this app is directed towards individuals in the United States, but a Canadian version may be released in upcoming months. This app gives users the tools and resources to research different classes of offenses and the repercussions one would receive if convicted. Although this app is informative, advice from law enforcement, attorneys, and other members of the law should be considered more accurate as it may suit your personal needs regarding a specific case. To start off, choose any of the classes on the left hand side, or calculate a sentence and the repercussions that would follow."
android:id="#+id/textView2"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:password="false"
android:phoneNumber="false"
android:singleLine="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp" />
</RelativeLayout>
</ScrollView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome"
android:id="#+id/textView"
android:textColor="#ffffff"
android:layout_above="#+id/scrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp" />
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/menuBackgroundColor"
android:choiceMode="singleChoice"
android:divider="#color/colorAccent"
android:dividerHeight="1dp"
android:paddingTop="15dp"/>
<!-- because there is no header in this one I am using android:paddingTop="15dp"
to push the menu below the level of the translucent top bar.-->
One of my Navdrawer pages (Same one as in screenshots)
Fragment
package nota.outlawsindex;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
import android.os.Bundle;
import android.os.PersistableBundle;
import android.support.v4.app.Fragment;
import android.support.v7.app.AppCompatActivity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.TextView;
public class TableFragment extends Fragment {
Button MisdemeanorClassAButton = null;
Button MisdemeanorClassBButton = null;
Button MisdemeanorClassCButton = null;
Button MisdemeanorClassDButton = null;
TextView MisdemeanorText;
public TableFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_table, container, false);
init(rootView);
return rootView;
}
public void init(View view) {
MisdemeanorClassAButton = (Button) view.findViewById(R.id.MisdemeanorClassAButton);
MisdemeanorText = (TextView) view.findViewById(R.id.MisdemeanorText);
MisdemeanorClassAButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MisdemeanorText.setText(R.string.MA);
}
}
);
MisdemeanorClassBButton = (Button) view.findViewById(R.id.MisdemeanorClassBButton);
MisdemeanorText = (TextView) view.findViewById(R.id.MisdemeanorText);
MisdemeanorClassBButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MisdemeanorText.setText(R.string.MB);
}
}
);
MisdemeanorClassCButton = (Button) view.findViewById(R.id.MisdemeanorClassCButton);
MisdemeanorText = (TextView) view.findViewById(R.id.MisdemeanorText);
MisdemeanorClassCButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MisdemeanorText.setText(R.string.MC);
}
}
);
MisdemeanorClassDButton = (Button) view.findViewById(R.id.MisdemeanorClassDButton);
MisdemeanorText = (TextView) view.findViewById(R.id.MisdemeanorText);
MisdemeanorClassDButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View view) {
MisdemeanorText.setText(R.string.MD);
}
}
);
}
}
The Activity Page of one of the NavDrawer Pages
<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:orientation="vertical"
android:background="#color/backgroundColor">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/MTB"
android:id="#+id/MisdemeanorText"
android:textColor="#ffffff"
android:layout_row="6"
android:layout_column="1"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class A"
android:id="#+id/MisdemeanorClassAButton"
android:layout_marginTop="34dp"
android:layout_row="0"
android:layout_column="0"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class B"
android:id="#+id/MisdemeanorClassBButton"
android:layout_row="0"
android:layout_column="1"
android:layout_alignTop="#+id/MisdemeanorClassAButton"
android:layout_toRightOf="#+id/MisdemeanorClassAButton"
android:layout_toEndOf="#+id/MisdemeanorClassAButton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class C"
android:id="#+id/MisdemeanorClassCButton"
android:layout_alignTop="#+id/MisdemeanorClassBButton"
android:layout_toLeftOf="#+id/MisdemeanorClassDButton"
android:layout_toStartOf="#+id/MisdemeanorClassDButton" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Class D"
android:id="#+id/MisdemeanorClassDButton"
android:layout_alignBottom="#+id/MisdemeanorClassCButton"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>

The issue is with your layout.
Two approaches to fix your problem -
Whenever you instantiate any fragment by selecting any option from the navigation drawer, you can set ScrollView (containing the welcome text) visibility to GONE.
Scrollview scrollView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
...
scrollView = (ScrollView) findViewById(R.id.scrollView);
}
private void selectItem(int position) {
scrollView.setVisibility(View.GONE);
....
}
Create a one more fragment with the layout where you only show your welcome text and launch this fragment in onCreate() of your activity. So this will show the welcome text when user starts your app. and when user selects any item from Navdrawer, you can launch another fragment of your choice. But for this you should remove welcome text from activity layout xml.

Related

Make ScrollView Gone when changing Nav Drawer Pages

I want my scrollview to have its visibiility set to gone whne i chose one of my nav drawer pages, i tried to do it with some help but got nullpointerexecptions and i got errors "Cannot Resolve Method setVisibility(int)" and Scrollview cannot be resolved,
MainActivity
package nota.outlawsindex;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.Button;
import android.widget.ListView;
import android.widget.ScrollView;
import android.widget.TextView;
import android.widget.Toast;
import org.w3c.dom.Text;
public class MainActivity extends AppCompatActivity {
private String[] mNavigationDrawerItemTitles;
private DrawerLayout mDrawerLayout;
private ListView mDrawerList;
Toolbar toolbar;
Scrollview scrollView;
private CharSequence mDrawerTitle;
private CharSequence mTitle;
android.support.v7.app.ActionBarDrawerToggle mDrawerToggle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mTitle = mDrawerTitle = getTitle();
mNavigationDrawerItemTitles = getResources().getStringArray(R.array.navigation_drawer_items_array);
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerList = (ListView) findViewById(R.id.left_drawer);
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
setupToolbar();
DataModel[] drawerItem = new DataModel[4];//need to update this if you add start counting at 0
drawerItem[0] = new DataModel(R.drawable.ic_connect, "Calculate Sentence");
drawerItem[1] = new DataModel(R.drawable.ic_fixtures, "Felonies");
drawerItem[2] = new DataModel(R.drawable.ic_table, "Misdemeanors");
drawerItem[3] = new DataModel(R.drawable.ic_drawer, "Infractions");
//add on to the list to create more pages
getSupportActionBar().setDisplayHomeAsUpEnabled(false);
getSupportActionBar().setHomeButtonEnabled(true);
DrawerItemCustomAdapter adapter = new DrawerItemCustomAdapter(this, R.layout.list_view_item_row, drawerItem);
mDrawerList.setAdapter(adapter);
mDrawerList.setOnItemClickListener(new DrawerItemClickListener());
mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
mDrawerLayout.setDrawerListener(mDrawerToggle);
setupDrawerToggle();
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
selectItem(position);
}
}
private void selectItem(int position) {
scrollView.setVisibility(View.GONE);
Fragment fragment = null;
switch (position) {
case 0:
fragment = new ConnectFragment();
break;
case 1:
fragment = new FixturesFragment();
break;
case 2:
fragment = new TableFragment();
break;
case 3:
fragment = new SelfAddedFragment();
break;
//add more cases if you add more pages
default:
break;
}
if (fragment != null) {
FragmentManager fragmentManager = getSupportFragmentManager();
fragmentManager.beginTransaction().replace(R.id.content_frame, fragment).commit();
mDrawerList.setItemChecked(position, true);
mDrawerList.setSelection(position);
setTitle(mNavigationDrawerItemTitles[position]);
mDrawerLayout.closeDrawer(mDrawerList);
} else {
Log.e("MainActivity", "Error in creating fragment");
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
//
int id = item.getItemId();
//
if (mDrawerToggle.onOptionsItemSelected(item)) {
return true;
} else if (id == R.id.action_settings) {
Toast.makeText(getApplicationContext(), "Settings", Toast.LENGTH_SHORT).show();
return true;
}
Toast.makeText(getApplicationContext(), "Search", Toast.LENGTH_SHORT).show();
return super.onOptionsItemSelected(item);
}
#Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
mDrawerToggle.syncState();
}
void setupToolbar() {
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
//getSupportActionBar().setDisplayShowHomeEnabled(true);
}
void setupDrawerToggle() {
mDrawerToggle = new android.support.v7.app.ActionBarDrawerToggle(this, mDrawerLayout, toolbar, R.string.app_name, R.string.app_name);
//This is necessary to change the icon of the Drawer Toggle upon state change.
mDrawerToggle.syncState();
}
}
Activity_Main
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/backgroundColor"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:id="#+id/relativeLayout"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</RelativeLayout>
<FrameLayout
android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/container_toolbar"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
</FrameLayout>
<include
android:id="#+id/toolbar"
layout="#layout/toolbar"
android:layout_gravity="right|top"
android:layout_below="#+id/scrollView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="26dp"
android:layout_marginStart="26dp" />
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/scrollView"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/content_frame"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/relativeLayout2"
android:focusable="false">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text=" Welcome to The Outlaw&apos;s Index! An app designed for individuals who want to educate themselves with knowledge regarding different types of offenses in the United States. Currently this app is directed towards individuals in the United States, but a Canadian version may be released in upcoming months. This app gives users the tools and resources to research different classes of offenses and the repercussions one would receive if convicted. Although this app is informative, advice from law enforcement, attorneys, and other members of the law should be considered more accurate as it may suit your personal needs regarding a specific case. To start off, choose any of the classes on the left hand side, or calculate a sentence and the repercussions that would follow."
android:id="#+id/textView2"
android:textColor="#ffffff"
android:paddingLeft="10dp"
android:paddingRight="10dp"
android:password="false"
android:phoneNumber="false"
android:singleLine="false"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="33dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Welcome"
android:id="#+id/textView"
android:textColor="#ffffff"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginLeft="27dp"
android:layout_marginStart="27dp" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
</RelativeLayout>
<ListView
android:id="#+id/left_drawer"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:background="#color/menuBackgroundColor"
android:choiceMode="singleChoice"
android:divider="#color/colorAccent"
android:dividerHeight="1dp"
android:paddingTop="15dp"/>
<!-- because there is no header in this one I am using android:paddingTop="15dp"
to push the menu below the level of the translucent top bar.-->
This is API 15, also im new to android development
Change this line:
ScrollView scrollView = (ScrollView) findViewById(R.id.scrollView);
to this line:
scrollView = (ScrollView) findViewById(R.id.scrollView);

Cannot find symbol variable drawer_layout

I have been trying to implement a Navigation Drawer in Android. I have been following this throughout the implementation. It seems that drawer_layout is not getting resolved from the R file. I can't seem to find where have I gone wrong. Here is my code:
MainActivity.java
package com.project.breadcrumbs.activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import com.project.breadcrumbs.R;
import com.project.breadcrumbs.helper.SQLiteHandler;
import com.project.breadcrumbs.helper.SessionManager;
import java.util.HashMap;
public class MainActivity extends AppCompatActivity implements FragmentDrawer.FragmentDrawerListener {
private Toolbar mToolbar;
private FragmentDrawer drawerFragment;
private DrawerLayout mDrawerLayout;
private TextView txtName;
private TextView txtEmail;
private Button btnLogout;
private SQLiteHandler db;
private SessionManager session;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(com.project.breadcrumbs.R.layout.activity_main);
mToolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(mToolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
drawerFragment = (FragmentDrawer)
getSupportFragmentManager().findFragmentById(R.id.fragment_navigation_drawer);
drawerFragment.setUp(R.id.fragment_navigation_drawer, (DrawerLayout) findViewById(R.id.drawer_layout), mToolbar);
drawerFragment.setDrawerListener(this);
txtName = (TextView) findViewById(R.id.name);
txtEmail = (TextView) findViewById(R.id.email);
btnLogout = (Button) findViewById(R.id.btnLogout);
// SqLite database handler
db = new SQLiteHandler(getApplicationContext());
// session manager
session = new SessionManager(getApplicationContext());
if (!session.isLoggedIn()) {
logoutUser();
}
// Fetching user details from sqlite
HashMap<String, String> user = db.getUserDetails();
String name = user.get("name");
String email = user.get("email");
// Displaying the user details on the screen
txtName.setText(name);
txtEmail.setText(email);
// Logout button click event
btnLogout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
logoutUser();
}
});
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onDrawerItemSelected(View view, int position) {
}
/**
* Logging out the user. Will set isLoggedIn flag to false in shared
* preferences Clears the user data from sqlite users table
* */
private void logoutUser() {
session.setLogin(false);
db.deleteUsers();
// Launching the login activity
Intent intent = new Intent(MainActivity.this, LoginActivity.class);
startActivity(intent);
finish();
}
}
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="${relativePackage}.${activityClass}">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:id="#+id/container_toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<include
android:id="#+id/toolbar"
layout="#layout/toolbar" />
</LinearLayout>
<FrameLayout
android:id="#+id/container_body"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
<fragment
android:id="#+id/fragment_navigation_drawer"
android:name="com.project.breadcrumbs.activity.FragmentDrawer"
android:layout_width="#dimen/nav_drawer_width"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="#layout/fragment_navigation_drawer"
tools:layout="#layout/fragment_navigation_drawer">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/welcome"
android:textSize="20dp" />
<TextView
android:id="#+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="10dp"
android:textColor="#color/lbl_name"
android:textSize="24dp" />
<TextView
android:id="#+id/email"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="13dp" />
<Button
android:id="#+id/btnLogout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="40dip"
android:background="#color/btn_logut_bg"
android:text="#string/btn_logout"
android:textAllCaps="false"
android:textColor="#color/white"
android:textSize="15dp" />
</LinearLayout>
</fragment>
</android.support.v4.widget.DrawerLayout>
I have tried 'dependencies' cannot be applied to '(groovy.lang.Closure)' and have tried to clean and then rebuild the project.
In your DrawerLayout Add Drawer Id:
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/drawer_layout"
tools:context="${relativePackage}.${activityClass}">

Custom Drawer Layout for Slide Over Action Bar

My requirement is i need the functionality of Navigation Drawer (Navigation Menu should appear both by clicking on the toggle icon and also dragging from margin) + Drawer layout on top of the action bar.
Check this post, i want the similar action.
I had gone through many post regarding this in SO itself, most of them saying to use a third-party library to use to get this done. But i don't want to use, instead in One SO question CommonsWare said like this can be done by tweaking the Drawerlayout.
How to achieve this?
Note: I don't want to use external library as it was creating problems.
In Android Default you cannot move the DrawerLayout along with the Action Bar. However if your are keen on using the Default Navigation Drawer. Hide the Action bar and create a Top layout similar to action bar. It will move with the drawerLayout. If you want further help code wise let me know.
Find my updated answer
MainActivity.java
package com.example.android.navigationdrawerexample;
import android.annotation.SuppressLint;
import android.os.Build;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentActivity;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.TranslateAnimation;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;
public class MainActivity extends FragmentActivity {
DrawerLayout drawerLayout;
ActionBarDrawerToggle drawerToggle;
ImageView menubtn, addbtn;
LinearLayout menuLayout;
RelativeLayout frame;
TranslateAnimation anim;
float moveFactor, lastTranslate = 0.0f;
ListView accList;
String[] menuValues = { "Add", "View" };
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.replace(R.id.container, new PlaceholderFragment())
.commit();
}
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
menuLayout = (LinearLayout) findViewById(R.id.menu);
accList = (ListView) findViewById(R.id.drawer_list);
frame = (RelativeLayout) findViewById(R.id.rl_main);
menubtn = (ImageView) findViewById(R.id.menu_btn);
addbtn = (ImageView) findViewById(R.id.add_btn);
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, menuValues);
accList.setAdapter(adapter);
drawerToggle = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_drawer, R.string.open, R.string.close) {
public void onDrawerClosed(View view) {
}
public void onDrawerOpened(View drawerview) {
// adapter = new AccountAdapter(this, R.layout.row_acc, values);
}
#SuppressLint("NewApi")
public void onDrawerSlide(View drawerView, float slideOffset) {
// use this code only if you need the fragment to slide over, if you want the
// drawerlayout to be above the main screen then ignore this code.
//moveFactor = (menuLayout.getWidth() * slideOffset);
//drawerLayout.setDrawerShadow(R.drawable.drawer_shadow,
// Gravity.LEFT);
//if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
// frame.setTranslationX(moveFactor);
//} else {
// anim = new TranslateAnimation(lastTranslate, moveFactor,
// 0.0f, 0.0f);
// anim.setDuration(0);
// anim.setFillAfter(true);
// frame.startAnimation(anim);
// lastTranslate = moveFactor;
//}
}
};
drawerLayout.setDrawerListener(drawerToggle);
menubtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (drawerLayout.isDrawerVisible(Gravity.LEFT)) {
return;
} else {
drawerLayout.openDrawer(Gravity.LEFT);
}
}
});
accList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if (position == 0) {
// Write your code
drawerLayout.closeDrawers();
}
}
});
addbtn.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "Action Bar Icon code as per your requirement", Toast.LENGTH_LONG).show();
}
});
}
/**
* A placeholder fragment containing a simple view.
*/
public static class PlaceholderFragment extends Fragment {
public PlaceholderFragment() {
}
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_planet, container,
false);
return rootView;
}
}
}
activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawer_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#android:color/white"
tools:context=".MainActivity" >
<RelativeLayout
android:id="#+id/rl_main"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="#+id/top_layout"
android:layout_width="match_parent"
android:layout_height="40dp" >
<ImageView
android:id="#+id/menu_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_marginLeft="10dp"
android:src="#drawable/ic_drawer" />
<ImageView
android:id="#+id/add_btn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:src="#android:drawable/ic_dialog_info"/>
</RelativeLayout>
<FrameLayout
android:id="#+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/top_layout" />
</RelativeLayout>
<!-- The navigation drawer -->
<LinearLayout
android:id="#+id/menu"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#android:color/white"
android:orientation="vertical" >
<TextView
android:id="#+id/welcome_text"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_marginLeft="20dp"
android:gravity="center_vertical"
android:text="OPEN" />
<ListView
android:id="#+id/drawer_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="20dp"
android:choiceMode="singleChoice"
android:divider="#android:color/white"
android:dividerHeight="2dp"
android:listSelector="#android:color/white" />
</LinearLayout>
</android.support.v4.widget.DrawerLayout>
And another important part Please change your application theme to noActionbar. Let me know if this satisfies your requirements.
Have you checked the Navigation Drawer documentation already? You have to provide a layout for the navigation drawer anyways, so it's always custom and up to you how it looks like.

Android Navigation Drawer not being closed by dragging it

I'm trying to implement a Navigation Drawer and I managed successfully to integrate it with the Action Bar: it opens and closes when the application button is pressed and it closes when I press on a blank part of the screen, but it does not allow to be dragged back to its original position. Once opened, I can't close it with a swipe (as in every application I have seen so far).
Here is my Java code:
package com.example.notificationswhisperer;
import java.util.ArrayList;
import java.util.List;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
public class MainActivity
extends Activity {
private DrawerLayout drawerLayout;
private ListView drawerList;
private ActionBarDrawerToggle drawerToggle;
private List<AppDrawerItem> drawerItems;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_notifications_whisperer);
drawerItems = new ArrayList<AppDrawerItem>();
drawerItems.add(
new AppDrawerItem("Settings",
getResources().getDrawable(R.drawable.ic_action_settings)));
drawerItems.add(
new AppDrawerItem("Test",
getResources().getDrawable(R.drawable.ic_action_settings)));
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setHomeButtonEnabled(true);
drawerLayout = (DrawerLayout) findViewById(R.id.layout_app_drawer);
drawerToggle = new ActionBarDrawerToggle(
this, // Context
drawerLayout, // DrawerLayout object
R.drawable.ic_drawer, // Drawer icon
0, // Open Drawer description
0) { // Closed Drawer description
public void onDrawerOpened(View view) {
super.onDrawerOpened(view);
invalidateOptionsMenu();
}
public void onDrawerSlide(View view, float offset) {
if (offset > .5) {
onDrawerOpened(view);
} else {
onDrawerClosed(view);
}
}
public void onDrawerClosed(View view) {
super.onDrawerClosed(view);
invalidateOptionsMenu();
}
};
drawerLayout.setDrawerListener(drawerToggle);
drawerLayout.setDrawerShadow(R.drawable.drawer_shadow, Gravity.START);
drawerList = (ListView) findViewById(R.id.list_app_drawer);
drawerList.setAdapter(new AppDrawerAdapter(this, drawerItems));
drawerList.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
drawerList.setItemChecked(position, true);
drawerLayout.closeDrawer(drawerList);
}
});
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
// Sync the toggle state after onRestoreInstanceState has occurred.
drawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration config) {
super.onConfigurationChanged(config);
drawerToggle.onConfigurationChanged(config);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.notifications_whisperer, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
if (drawerToggle.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
This is my layout for the activity:
<android.support.v4.widget.DrawerLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/layout_app_drawer"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.notificationswhisperer.NotificationsWhisperer" >
<ListView
android:id="#+id/list_app_drawer"
android:layout_width="280dp"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/black"
android:dividerHeight="0.5dp"
android:background="#android:color/white" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world" />
</android.support.v4.widget.DrawerLayout>
And this is for the List entries:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="48dp"
android:orientation="vertical" >
<ImageView
android:id="#+id/list_item_app_drawer_image"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/list_item_app_drawer_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="8dp"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/list_item_app_drawer_image"
android:textSize="18sp" />
</RelativeLayout>
Am I missing something? Thank you in advance.
ADDENDUM: Additionally, the back button won't close the Drawer.
I had the very same issue : the drawer could be opened by a swipe, but could only be closed by a click on the actionbar button.
After some research, it appeared that the underlying activity had several critical bugs : some fragments were added which were adding an un-initialized pager (with a null adapter)
Anyway, when I fixed these bugs (which had nothing to do with the drawer implementation), then behavior went correct.

Using getFragmentManager on a ListActivity

I just want to know if this is possible since first. I have created a custom listView based on the tutorial I read from Sai Geetha. Well it works perfectly on my app except that it needs to extend ListActivity instead of FragmentActivity. Now I'm having a hard time configuring and adding a dialog for this since I need to apply a fragment dialog and I can't use the getFragmentManager() since I'm not working with the FragmentActivity. Is there's another way I can do to work on this without sacrificing the ListActivity? Thanks!
Here's my code so far
XML:
conversation_list_view
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#id/android:list"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:layout_marginTop="20dp"/>
</LinearLayout>
group_screen
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="48dp"
android:background="#drawable/action_bar_separator"
android:id="#+id/relativeLayout">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Group Name"
android:id="#+id/txt_group_name"
android:layout_centerVertical="true"
android:layout_centerHorizontal="true"
android:textColor="#color/dark_gray"
android:shadowColor="#color/dark_shadow"
android:shadowRadius="1"
android:shadowDy="1"/>
<Button
android:layout_width="32dp"
android:layout_height="32dp"
android:id="#+id/btn_back"
android:background="#drawable/btn_navigate_back"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"/>
<Button
android:layout_width="32dp"
android:layout_height="32dp"
android:id="#+id/btn_information"
android:background="#drawable/btn_information"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_marginTop="10dp"
android:layout_marginRight="10dp"/>
</RelativeLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Conversations"
android:id="#+id/textView2"
android:textColor="#color/holo_light_blue"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="340dp"
>
<fragment
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:name="com.mark.exercise.ListViewFragment"
android:id="#+id/fragment"/>
</LinearLayout>
<Button
android:layout_width="match_parent"
android:layout_height="42dp"
android:text="Ask something"
android:id="#+id/btn_ask_question"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:textSize="15dp"/>
</LinearLayout>
</LinearLayout>
Java
package com.mark.exercise;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.FragmentActivity;
import android.support.v4.app.FragmentManager;
import android.view.View;
import android.widget.Button;
import android.widget.ListView;
import android.widget.TextView;
/**
* Created by pc on 9/24/13.
*/
public class GroupActivity extends FragmentActivity {
Button information, back, new_topic;
ListView conversations;
TextView group_name;
String name, group_description, group_administrator,image_id;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.group_screen);
Intent intent = getIntent();
name = intent.getStringExtra("group_name");
group_description = intent.getStringExtra("group_description");
group_administrator = intent.getStringExtra("group_administrator");
image_id = intent.getStringExtra("image_id");
information = (Button)findViewById(R.id.btn_information);
back = (Button)findViewById(R.id.btn_back);
new_topic = (Button)findViewById(R.id.btn_ask_question);
group_name = (TextView)findViewById(R.id.txt_group_name);
group_name.setText(name);
information.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
Intent intent = new Intent(GroupActivity.this, GroupInformationActivity.class);
intent.putExtra("group_name",name);
intent.putExtra("group_description",group_description);
intent.putExtra("group_administrator",group_administrator);
intent.putExtra("image_id",image_id);
startActivity(intent);
GroupActivity.this.overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
}
});
new_topic.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
showCreateNewTopicDialog();
}
});
back.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
onBackPressed();
}
});
}
private void showCreateNewTopicDialog() {
FragmentManager fm = getSupportFragmentManager();
DialogFragmentCreateGroup createGroup = new DialogFragmentCreateGroup();
createGroup.show(fm, "create_group");
}
#Override
public void onBackPressed(){
super.onBackPressed();
overridePendingTransition(R.anim.in_from_right,R.anim.out_to_left);
}
}
List Fragment
package com.mark.exercise;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ListFragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ListView;
import android.widget.SimpleAdapter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Random;
/**
* Created by pc on 9/27/13.
*/
public class ListViewFragment extends ListFragment {
final ArrayList<HashMap<String,String>> list = new ArrayList<HashMap<String,String>>();
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.conversations_list_view,
container, false);
setListView set_list = new setListView();
set_list.start();
return view;
}
public void onListItemClick(ListView l, View v, int position, long id) {
//super.onListItemClick(l, v, position, id);
Intent intent = new Intent(getActivity(), ConversationActivity.class);
startActivity(intent);
getActivity().overridePendingTransition(R.anim.in_from_left, R.anim.out_to_right);
}
private class setListView extends Thread {
public void run() {
getActivity().runOnUiThread(new Runnable() {
#Override
public void run() {
setConversations();
}
});
}
}
private void setConversations(){
list.clear();
SimpleAdapter adapter = new SimpleAdapter(
getActivity(),
list,
R.layout.custom_list_main_conversations,
new String[] {"message","date", "reply_count", "stars_count"},
new int[] {R.id.txt_conversation_message,R.id.txt_topic_date, R.id.txt_no_of_reply, R.id.txt_no_of_stars}
);
for(int ctr=0;ctr<=5;ctr++){
Random randomGenerator = new Random();
HashMap<String,String> item_list = new HashMap<String,String>();
item_list.put("message", "This is the conversation number "+(ctr+1)+" and this topic is just a dummy data.");
item_list.put("date", "0"+(ctr+1)+"/0"+(ctr+2)+"/2013 "+(ctr+1)+":00:am");
item_list.put("reply_count", String.valueOf(ctr+randomGenerator.nextInt(10)));
item_list.put("stars_count", String.valueOf(ctr+randomGenerator.nextInt(10)));
list.add(item_list);
}
android.app.ListFragment lf = new android.app.ListFragment();
lf.setListAdapter(adapter);
}
}
You can use ListFragment inside FragmentActivity instead of using a ListActivity.

Categories

Resources