Not able to open MainActivity getting nullPointer exception - android

MainActivity.java
package com.pKLabs.RgpvDigest;
import android.content.ActivityNotFoundException;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Paint;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.Bundle;
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuItem;
import android.view.MenuItem.OnMenuItemClickListener;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.view.animation.AlphaAnimation;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.AnimationUtils;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;
import cssyllabus.MainCS;
import static com.pKLabs.RgpvDigest.R.layout.activity_main;
public class MainActivity extends ActionBarActivity implements
OnItemClickListener, AnimationListener {
private DrawerLayout drawerLayout;
private ListView listView;
private ActionBarDrawerToggle drawerListner;
TextView t, t1, t2, t3, t4, t5;
Animation rotation, anim;
private MyAdapter myAdapter;
private static final String AD_UNIT_ID = "ca-app-pub-8935153656417807/4125750777";
private static final String TAG = "MainActivity";
private InterstitialAd iAd;
ImageView iv;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
anim = new AlphaAnimation(0.0f, 1.0f);
anim.setDuration(60); // You can manage the blinking time with this
// parameter
anim.setStartOffset(30);
anim.setRepeatMode(Animation.REVERSE);
anim.setRepeatCount(2);
iv = (ImageView) findViewById(R.id.imageView1);
rotation = AnimationUtils.loadAnimation(getApplicationContext(),
R.anim.button_rotate);
rotation.setRepeatCount(Animation.INFINITE);
rotation.setAnimationListener(MainActivity.this);
iv.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
iv.startAnimation(rotation);
t1.startAnimation(anim);
t2.startAnimation(anim);
t3.startAnimation(anim);
t4.startAnimation(anim);
t5.startAnimation(anim);
}
});
t = (TextView) findViewById(R.id.rgpvtext);
t.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
iv.startAnimation(rotation);
t1.startAnimation(anim);
t2.startAnimation(anim);
t3.startAnimation(anim);
t4.startAnimation(anim);
t5.startAnimation(anim);
}
});
Typeface tf = Typeface.createFromAsset(getApplicationContext()
.getAssets(), "segoe.ttf");
TextView t = (TextView) findViewById(R.id.rgpvtext);
t.setTypeface(tf);
t.setTypeface(tf, tf.BOLD);
iAd = new InterstitialAd(this);
iAd.setAdUnitId(AD_UNIT_ID);
iAd.setAdListener(new AdListener() {
#Override
public void onAdLoaded() {
}
#Override
public void onAdFailedToLoad(int errorCode) {
}
});
loadInterstitial();
listView = (ListView) findViewById(R.id.drawerlist);
myAdapter = new MyAdapter(this);
listView.setAdapter(myAdapter);
listView.setOnItemClickListener(this);
drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
drawerListner = new ActionBarDrawerToggle(this, drawerLayout,
R.drawable.ic_drawer, R.string.dopen, R.string.dclose);
drawerLayout.setDrawerListener(drawerListner);
getSupportActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
t1 = (TextView) findViewById(R.id.compu);
t1.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
t1.setTypeface(tf);
t1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Semester.class);
startActivityForResult(intent, 0);
}
});
t2 = (TextView) findViewById(R.id.calc);
t2.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
t2.setTypeface(tf);
t2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), Calculator.class);
startActivityForResult(intent, 0);
}
});
t3 = (TextView) findViewById(R.id.iv);
t3.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
t3.setTypeface(tf);
t3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(),
InterviewQuestion.class);
startActivityForResult(intent, 0);
}
});
t4 = (TextView) findViewById(R.id.prog);
t4.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
t4.setTypeface(tf);
t4.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(v.getContext(), Programs.class);
startActivityForResult(intent, 0);
}
});
t5 = (TextView) findViewById(R.id.abo);
t5.setPaintFlags(Paint.UNDERLINE_TEXT_FLAG);
t5.setTypeface(tf);
t5.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(v.getContext(), About.class);
startActivityForResult(intent, 0);
}
});
}
private void loadInterstitial() {
// TODO Auto-generated method stub
AdRequest adRequest = new AdRequest.Builder().build();
iAd.loadAd(adRequest);
System.out.println("Ad loaded success");
}
public void showInterstitial() {
if (iAd.isLoaded()) {
iAd.show();
System.out.println("Ad shown success");
} else {
Log.d(TAG, "Interstitial ad is not loaded yet");
}
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
drawerListner.onConfigurationChanged(newConfig);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onPostCreate(savedInstanceState);
drawerListner.syncState();
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuItem item = menu.add("share"); // your desired title here
item.setIcon(R.drawable.share_icon); // your desired icon here
item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
item.setOnMenuItemClickListener(new OnMenuItemClickListener() {
#Override
public boolean onMenuItemClick(MenuItem item) {
try
{ Intent i = new Intent(Intent.ACTION_SEND);
i.setType("text/plain");
i.putExtra(Intent.EXTRA_SUBJECT, "RGPV Digest");
String sAux = "Looking to score high in RGPV ?\n Try out this app :\n\n";
sAux = sAux + "https://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName();
i.putExtra(Intent.EXTRA_TEXT, sAux);
startActivity(Intent.createChooser(i, "Share via"));
}
catch(Exception e)
{ //e.toString();
}
return true;
}
});
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
if (id == R.id.action_settings) {
return true;
}
if (drawerListner.onOptionsItemSelected(item)) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id) {
if (position == 0) {
Uri uri = Uri
.parse("https://2ce74af0d8de8783b91cdd315eeba0340a4b9277.googledrive.com/host/0B2sDUzNeIK0KODB0ZDRMVjFPaFE/Jobs.html");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
} else if (position == 1) {
Intent intent = new Intent(this, MainCS.class);
startActivityForResult(intent, 0);
} else if (position == 2) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","laboratorypk#gmail.comm", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "Project Help");
intent.putExtra(Intent.EXTRA_TEXT,"Please write a short description of your project and technology you are supposed to use.");
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
// }
else if (position == 3) {
Intent intent = new Intent(this, Careerguid.class);
startActivityForResult(intent, 0);
}
else if (position == 4) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","laboratorypk#gmail.comm", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "PC Games");
intent.putExtra(Intent.EXTRA_TEXT,"Hey! I need PC Games pls share the list of Games that you have.");
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
else if (position == 5) {
Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
Intent goToMarket = new Intent(Intent.ACTION_VIEW, uri);
try {
startActivity(goToMarket);
} catch (ActivityNotFoundException e) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("http://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName())));
}
}
else if (position == 6) {
Intent intent = new Intent(Intent.ACTION_SENDTO, Uri.fromParts(
"mailto","laboratorypk#gmail.comm", null));
intent.putExtra(Intent.EXTRA_SUBJECT, "Query/Feedback");
intent.putExtra(Intent.EXTRA_TEXT,"");
startActivity(Intent.createChooser(intent, "Choose an Email client :"));
}
drawerLayout.closeDrawers();
selectItem(position);
}
public void selectItem(int position) {
// TODO Auto-generated method stub
listView.setItemChecked(position, true);
}
public void setTitle(String title) {
getSupportActionBar().setTitle(title);
}
#Override
protected void onDestroy() {
// TODO Auto-generated method stub
showInterstitial();
super.onDestroy();
}
private Toast toast;
private long lastBackPressTime = 0;
#Override
public void onBackPressed() {
if (this.lastBackPressTime < System.currentTimeMillis() - 4000) {
toast = Toast.makeText(this, "Press back again to exit",
Toast.LENGTH_LONG);
toast.show();
this.lastBackPressTime = System.currentTimeMillis();
drawerLayout.closeDrawers();
} else {
if (toast != null) {
toast.cancel();
}
super.onBackPressed();
}
}
#Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationEnd(Animation animation) {
// TODO Auto-generated method stub
}
#Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}
}
class MyAdapter extends BaseAdapter {
private Context context;
String[] navlist;
int[] images = { R.drawable.job, R.drawable.facebook, R.drawable.project,
R.drawable.career, R.drawable.games, R.drawable.rate, R.drawable.mail };
public MyAdapter(Context context) {
this.context = context;
navlist = context.getResources().getStringArray(R.array.navdra);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return navlist.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return navlist[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
View row = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.customrow, parent, false);
}
else {
row = convertView;
}
TextView titleTextView = (TextView) row.findViewById(R.id.textView11);
ImageView titleImageView = (ImageView) row
.findViewById(R.id.imageView1);
titleTextView.setText(navlist[position]);
titleImageView.setImageResource(images[position]);
return row;
}
}
Here is activity_main.xml
<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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/ab" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="135dp"
android:layout_height="135dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="30dp"
android:src="#drawable/rgpvicon" />
<TextView
android:id="#+id/rgpvtext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageView1"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="6dp"
android:clickable="true"
android:text="RGPV Digest"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#drawable/texteff"
android:textSize="36sp" />
<TextView
android:id="#+id/compu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/rgpvtext"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_marginTop="25dp"
android:clickable="true"
android:text="Computer Science"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/texteff"
android:textSize="24sp" />
<TextView
android:id="#+id/calc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/compu"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:text="Calculator"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/texteff"
android:textSize="24sp" />
<TextView
android:id="#+id/iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/calc"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:text="Interview Question"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/texteff"
android:textSize="24sp" />
<TextView
android:id="#+id/prog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/iv"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:text="Programs"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/texteff"
android:textSize="24sp" />
<TextView
android:id="#+id/abo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/prog"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:clickable="true"
android:text="About"
android:paddingBottom="20dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#drawable/texteff"
android:textSize="24sp" />
</RelativeLayout>
</ScrollView>
</LinearLayout>
<ListView
android:id="#+id/drawerlist"
android:layout_width="240dp"
android:layout_height="match_parent"
android:layout_gravity="left"
android:background="#4ABC96"
android:paddingTop="6dp" />
</android.support.v4.widget.DrawerLayout>
LOG:
Process: com.pKLabs.RgpvDigest, PID: 1557
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.pKLabs.RgpvDigest/com.pKLabs.RgpvDigest.MainActivity}: java.lang.NullPointerException
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2184)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
at android.app.ActivityThread.access$800(ActivityThread.java:135)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:136)
at android.app.ActivityThread.main(ActivityThread.java:5001)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:515)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
at dalvik.system.NativeStart.main(Native Method)
Caused by: java.lang.NullPointerException
at com.pKLabs.RgpvDigest.MainActivity.onCreate(MainActivity.java:146)
at android.app.Activity.performCreate(Activity.java:5231)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1087)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2148)
            at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2233)
            at android.app.ActivityThread.access$800(ActivityThread.java:135)
            at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1196)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:136)
            at android.app.ActivityThread.main(ActivityThread.java:5001)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:785)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:601)
            at dalvik.system.NativeStart.main(Native Method)
07-23 07:04:44.900 409-763/? W/ActivityManager﹕ Force finishing activity com.pKLabs.RgpvDigest/.MainActivity
07-23 07:04:45.080 409-428/? D/dalvikvm﹕ GC_FOR_ALLOC freed 312K, 54% free 5989K/12960K, paused 98ms, total 101ms
07-23 07:04:45.410 1557-1574/? D/dalvikvm﹕ DexOpt: --- BEGIN 'ads1355421311.jar' (bootstrap=0) ---
07-23 07:04:45.510 409-428/? I/Choreographer﹕ Skipped 38 frames! The application may be doing too much work on its main thread.
Not able to figure out what am i doing wrong, i updated android studio and downloaded API 22 and after that i got many errors in My gradle too. I some how fixed that but it is run time error how can i fix please help me out.

Is your activity added in the manifest?

use getSupportActionBar() instead of getActionBar().
Use
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Instead of
getActionBar().setDisplayHomeAsUpEnabled(true);
and run the app again.

Related

whenever i run the app on emulator it says unfortunately the app has stopped working and the log reads as below

MainActivity.java
package com.example.intel.dualboot;
import android.annotation.TargetApi;
import android.app.AlertDialog;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.content.DialogInterface;
import android.content.Intent;
import android.content.res.Configuration;
import android.os.Build;
import android.preference.PreferenceManager;
import android.support.v4.widget.DrawerLayout;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.ActionBar;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.SpannableString;
import android.text.method.LinkMovementMethod;
import android.text.util.Linkify;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity implements StatusAsyncTask.StatusAsyncTaskListener, SwipeRefreshLayout.OnRefreshListener, MainActivityListener {
private static final String TAG = "db::MainActivity";
/* public static final int ACT_INSTALL_ROM = 1;
public static final int ACT_CHANGE_PAGE = 2;
public static final int ACT_SELECT_ICON = 3;
public static final int ACT_UNINSTALL_ROM = 4;
public static final String INTENT_EXTRA_SHOW_ROM_LIST = "show_rom_list";*/
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(Build.VERSION.SDK_INT == 20) {
showDeprecatedLAlert();
return;
}
setContentView(R.layout.activity_main);
// This activity is using different background color, which would cause overdraw
// of the whole area, so disable the default background
getWindow().setBackgroundDrawable(null);
Utils.installHttpCache(this);
PreferenceManager.setDefaultValues(this, R.xml.settings, false);
m_srLayout = (InSwipeRefreshLayout)findViewById(R.id.refresh_layout);
m_srLayout.setOnRefreshListener(this);
m_curFragment = -1;
m_fragmentTitles = getResources().getStringArray(R.array.main_fragment_titles);
m_drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
m_drawerList = (ListView) findViewById(R.id.left_drawer);
String[] fragmentClsNames = new String[MainFragment.MAIN_FRAG_CNT];
for(int i = 0; i < fragmentClsNames.length; ++i)
fragmentClsNames[i] = MainFragment.getFragmentClass(i).getName();
m_fragments = new MainFragment[MainFragment.MAIN_FRAG_CNT];
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction t = fragmentManager.beginTransaction();
for(int i = 0; i < m_fragments.length; ++i) {
m_fragments[i] = (MainFragment)fragmentManager.findFragmentByTag(fragmentClsNames[i]);
if(m_fragments[i] == null) {
m_fragments[i] = MainFragment.newFragment(i);
t.add(R.id.content_frame, m_fragments[i], fragmentClsNames[i]);
}
t.hide(m_fragments[i]);
}
t.commit();
// Set the adapter for the list view
m_drawerList.setAdapter(new ArrayAdapter<String>(this,
R.layout.drawer_list, m_fragmentTitles));
// Set the list's click listener
m_drawerList.setOnItemClickListener(new DrawerItemClickListener());
m_drawerTitle = getText(R.string.app_name);
m_drawerToggle = new ActionBarDrawerToggle(
this, m_drawerLayout, R.string.drawer_open, R.string.drawer_close) {
public void onDrawerClosed(View view) {
getSupportActionBar().setTitle(m_title);
}
public void onDrawerOpened(View drawerView) {
getSupportActionBar().setTitle(m_drawerTitle);
}
};
m_drawerLayout.setDrawerListener(m_drawerToggle);
final ActionBar bar = getSupportActionBar();
if(bar != null) {
bar.setDisplayHomeAsUpEnabled(true);
bar.setHomeButtonEnabled(true);
}
/* if (getIntent().hasExtra(INTENT_EXTRA_SHOW_ROM_LIST) &&
getIntent().getBooleanExtra(INTENT_EXTRA_SHOW_ROM_LIST, false)) {
getIntent().removeExtra(INTENT_EXTRA_SHOW_ROM_LIST);
selectItem(1);
} else if(savedInstanceState != null) {
selectItem(savedInstanceState.getInt("curFragment", 0));
} else {
selectItem(0);
}*/
}
/*#Override
protected void onNewIntent(Intent i) {
super.onNewIntent(i);
if (i.hasExtra(INTENT_EXTRA_SHOW_ROM_LIST) &&
i.getBooleanExtra(INTENT_EXTRA_SHOW_ROM_LIST, false)) {
selectItem(1);
}
}*/
#Override
protected void onStop() {
super.onStop();
Utils.flushHttpCache();
}
#Override
protected void onSaveInstanceState(Bundle outState) {
super.onSaveInstanceState(outState);
outState.putInt("curFragment", m_curFragment);
}
#Override
public boolean onCreateOptionsMenu (Menu menu) {
getMenuInflater().inflate(R.menu.main, menu);
m_refreshItem = menu.findItem(R.id.action_refresh);
if(!StatusAsyncTask.instance().isComplete())
m_refreshItem.setEnabled(false);
return true;
}
private class DrawerItemClickListener implements ListView.OnItemClickListener {
#Override
public void onItemClick(AdapterView parent, View view, int position, long id) {
selectItem(position);
}
}
/** Swaps fragments in the main content view */
private void selectItem(int position) {
if(position < 0 || position >= m_fragments.length) {
Log.e(TAG, "Invalid fragment index " + position);
return;
}
// Insert the fragment by replacing any existing fragment
FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction t = fragmentManager.beginTransaction();
if(m_curFragment != -1)
t.hide(m_fragments[m_curFragment]);
t.show(m_fragments[position]);
t.commit();
m_curFragment = position;
// Highlight the selected item, update the title, and close the drawer
m_drawerList.setItemChecked(position, true);
setTitle(m_fragmentTitles[position]);
m_drawerLayout.closeDrawer(m_drawerList);
}
#Override
public void setTitle(CharSequence title) {
m_title = title;
getSupportActionBar().setTitle(m_title);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
super.onPostCreate(savedInstanceState);
if(m_drawerToggle != null)
m_drawerToggle.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
if(m_drawerToggle != null)
m_drawerToggle.onConfigurationChanged(newConfig);
}
#Override
public boolean onOptionsItemSelected(MenuItem it) {
if (m_drawerToggle.onOptionsItemSelected(it))
return true;
switch(it.getItemId()) {
case R.id.action_refresh:
refresh(false);
return true;
case R.id.action_reboot:
{
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle("Reboot")
.setCancelable(true)
.setNegativeButton("Cancel", null)
.setItems(R.array.reboot_options, new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
switch (i) {
case 0: Utils.reboot(""); break;
case 1: Utils.reboot("recovery"); break;
case 2: Utils.reboot("bootloader"); break;
}
}
})
.create().show();
return true;
}
default:
return false;
}
}
public void startRefresh(boolean notifyRefreshLayout) {
if(notifyRefreshLayout)
m_srLayout.setRefreshing(true);
if(m_refreshItem != null)
m_refreshItem.setEnabled(false);
for(int i = 0; i < m_fragments.length; ++i)
m_fragments[i].startRefresh();
StatusAsyncTask.instance().setListener(this);
StatusAsyncTask.instance().execute();
}
#Override
public void refresh(boolean b) {
refresh(true);
}
#Override
public void setRefreshComplete() {
m_srLayout.setRefreshing(false);
if(m_refreshItem != null)
m_refreshItem.setEnabled(true);
for(int i = 0; i < m_fragments.length; ++i)
m_fragments[i].setRefreshComplete();
}
#Override
public void onFragmentViewCreated() {
if(++m_fragmentViewsCreated == m_fragments.length) {
// postDelayed because SwipeRefresher view ignores
// setRefreshing call otherwise
m_srLayout.postDelayed(new Runnable() {
#Override
public void run() {
Intent i = getIntent();
if(i == null || !i.getBooleanExtra("force_refresh", false)) {
startRefresh(true);
} else {
i.removeExtra("force_refresh");
refresh(false);
}
}
}, 1);
}
}
#Override
public void onFragmentViewDestroyed() {
--m_fragmentViewsCreated;
}
#Override
public void addScrollUpListener(InSwipeRefreshLayout.ScrollUpListener l) {
m_srLayout.addScrollUpListener(l);
}
#Override
public void onStatusTaskFinished(StatusAsyncTask.Result res) {
for(int i = 0; i < m_fragments.length; ++i)
m_fragments[i].onStatusTaskFinished(res);
}
#Override
public void onRefresh() {
refresh(false);
}
#TargetApi(20)
private void showDeprecatedLAlert() {
SpannableString msg = new SpannableString("Android Developer preview has bugs");
Linkify.addLinks(msg, Linkify.ALL);
AlertDialog.Builder b = new AlertDialog.Builder(this);
b.setTitle("Unsupported Android version")
.setCancelable(false)
.setMessage(msg)
.setNegativeButton("Exit Application", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
}
});
AlertDialog d = b.create();
d.show();
TextView msgView = (TextView)d.findViewById(android.R.id.message);
msgView.setMovementMethod(LinkMovementMethod.getInstance());
}
private DrawerLayout m_drawerLayout;
private ListView m_drawerList;
private String[] m_fragmentTitles;
private MainFragment[] m_fragments;
private int m_curFragment;
private CharSequence m_title;
private ActionBarDrawerToggle m_drawerToggle;
private CharSequence m_drawerTitle;
private MenuItem m_refreshItem;
private int m_fragmentViewsCreated;
private InSwipeRefreshLayout m_srLayout;
}
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout">
<com.example.intel.dualboot.InSwipeRefreshLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/refresh_layout"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<FrameLayout android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.example.intel.dualboot.InSwipeRefreshLayout>
<ListView android:id="#+id/left_drawer"
android:layout_width="#dimen/lviewdimen"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
Stack Trace
E/AndroidRuntime: FATAL EXCEPTION: main
Process: com.example.intel.dualboot, PID: 23319
java.lang.RuntimeException: Unable to start activity
ComponentInfo{com.example.intel.dualboot/com.example.intel.dualboot.MainActivity}:
java.lang.NullPointerException: Attempt to write to field
'android.app.FragmentManagerImpl
android.app.Fragment.mFragmentManager' on a null object reference
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2330)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392)
at android.app.ActivityThread.access$800(ActivityThread.java:154)
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308)
at android.os.Handler.dispatchMessage(Handler.java:102)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5273)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:908)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:703)
Caused by: java.lang.NullPointerException: Attempt to write to field
'android.app.FragmentManagerImpl
android.app.Fragment.mFragmentManager' on a null object reference
at android.app.BackStackRecord.doAddOp(BackStackRecord.java:469)
at android.app.BackStackRecord.add(BackStackRecord.java:464)
at com.example.intel.dualboot.MainActivity.onCreate(MainActivity.java:78)
at android.app.Activity.performCreate(Activity.java:6041)
at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1109)
at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2283)
at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2392) 
at android.app.ActivityThread.access$800(ActivityThread.java:154) 
at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1308) 
at android.os.Handler.dispatchMessage(Handler.java:102) 
at android.os.Looper.loop(Looper.java:135) 
at android.app.ActivityThread.main(ActivityThread.java:5273) 
at java.lang.reflect.Method.invoke(Native Method) 
at java.lang.reflect.Method.invoke(Method.java:372)
replace
com.exmaple.intel.dualboot.InSwipeRefreshLayout
with
android.support.v4.widget.SwipeRefreshLayout
in your xml file,
as the com.exmaple.intel.dualboot.InSwipeRefreshLayout class is not defined
com.exmaple.intel.dualboot.InSwipeRefreshLayout
Check this path if it is correct in your xml.It seems the path of "InSwipeRefreshLayout" is not corect
in your xml
<?xml version="1.0" encoding="utf-8"?><android.support.v4.widget.DrawerLayout 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:id="#+id/drawer_layout">
<com.exmaple.intel.dualboot.InSwipeRefreshLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/refresh_layout"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true">
<FrameLayout android:id="#+id/content_frame"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</com.exmaple.intel.dualboot.InSwipeRefreshLayout>
<ListView android:id="#+id/left_drawer"
android:layout_width="#dimen/lviewdimen"
android:layout_height="match_parent"
android:layout_gravity="start"
android:choiceMode="singleChoice"
android:divider="#android:color/transparent"
android:dividerHeight="0dp"
android:background="#111" />
</android.support.v4.widget.DrawerLayout>
the com.exmaple.intel.dualboot.InSwipeRefreshLayout has that spelling of "exmaple", it should be example.
The posted layout working fine for me.Please check the package name properly com.example.intel.dualboot.InSwipeRefreshLayout whether exist or not and clean and build the project.

Using Spinner Choose Language with Text To Speech?

My homework is a Text to speech app using Spinner choose Language.
but I do not know very much about this topic.
Here my code for MainActivity.java:
package com.detainhom6.doctext;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.speech.tts.TextToSpeech;
import android.speech.tts.TextToSpeech.OnInitListener;
import android.util.Log;
import android.view.Gravity;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.Toast;
import android.widget.AdapterView.OnItemSelectedListener;
public class MainActivity extends Activity implements OnInitListener{
// Khai bao cac bien can thiet
String chuoinhap;
String ngonngu[] = {"English", "Japan", "Korea", "China"};
EditText txtNhap;
Button btnNoi;
Toast note;
Spinner spnn;
//Khai bao bien text to speech
private TextToSpeech t2p;
private int kiemtradulieu = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// gan gia tri cho bien vua khai bao
txtNhap = (EditText)findViewById(R.id.txtnhap);
btnNoi = (Button)findViewById(R.id.btnNoi);
spnn = (Spinner)findViewById(R.id.menungonngu);
//
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_spinner_item, ngonngu);
adapter.setDropDownViewResource(android.R.layout.simple_list_item_single_choice);
spnn.setAdapter(adapter);
spnn.setOnItemSelectedListener(new ClickChonNgonNgu());
Intent kiemtrat2pintent = new Intent();
kiemtrat2pintent.setAction(TextToSpeech.Engine.ACTION_CHECK_TTS_DATA);
startActivityForResult(kiemtrat2pintent, kiemtradulieu);
btnNoi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View mangV) {
// TODO Auto-generated method stub
chuoinhap = txtNhap.getText().toString();
doc(chuoinhap);
}
});
}
// Tao Ham khi Goi Intent Acivity Result
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == kiemtradulieu){
if(resultCode == TextToSpeech.Engine.CHECK_VOICE_DATA_PASS){
t2p = new TextToSpeech(this,this);
}
else
{
Intent caidatt2pIntent = new Intent();
caidatt2pIntent.setAction(TextToSpeech.Engine.ACTION_INSTALL_TTS_DATA);
startActivity(caidatt2pIntent);
}
}
}
// Khoi Tao Ham Doc Chuoi Da Nhap
protected void doc(String chuoinhap2) {
// TODO Auto-generated method stub
t2p.speak(chuoinhap2, TextToSpeech.QUEUE_FLUSH, null);
}
// Tao su kien khi chon item trong Spinner
public class ClickChonNgonNgu implements OnItemSelectedListener{
#Override
public void onItemSelected(AdapterView<?> parent, View view,
int position, long id) {
// TODO Auto-generated method stub
String nndachon;
nndachon = ngonngu[position];
if(nndachon == "English"){
t2p.setLanguage(Locale.US);
note = Toast.makeText(MainActivity.this, "Bạn Dã Chọn English", Toast.LENGTH_SHORT);
note.setGravity(Gravity.CENTER, 0, 0);
note.show();
}
if(nndachon == "Japan"){
t2p.setLanguage(Locale.JAPAN);
note = Toast.makeText(MainActivity.this, "Bạn đã chọn Japan", Toast.LENGTH_SHORT);
note.setGravity(Gravity.CENTER, 0, 0);
note.show();
}
if(nndachon == "Korea"){
t2p.setLanguage(Locale.KOREA);
note = Toast.makeText(MainActivity.this, "Bạn đã chọn Korea", Toast.LENGTH_SHORT);
note.setGravity(Gravity.CENTER, 0, 0);
note.show();
}
if(nndachon == "China"){
t2p.setLanguage(Locale.CHINA);
note = Toast.makeText(MainActivity.this, "Bạn đã chọn China", Toast.LENGTH_SHORT);
note.setGravity(Gravity.CENTER, 0, 0);
note.show();
}
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
// TODO Auto-generated method stub
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.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();
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onInit(int status) {
// TODO Auto-generated method stub
if(status == TextToSpeech.SUCCESS)
{
t2p.setLanguage(Locale.US);
Log.e("TTS INIT", "TTS Thành Công");
}
else if(status == TextToSpeech.ERROR)
{
Log.e("TTS INIT", "TTS Lỗi");
}
}
}
And here is the activity_main.xml:
<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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.detainhom6.doctext.MainActivity" >
<TextView
android:id="#+id/txtnote"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/note1" />
<Button
android:id="#+id/btnNoi"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtnhap"
android:layout_below="#+id/txtnhap"
android:layout_marginTop="21dp"
android:text="#string/Button_Noi" />
<EditText
android:id="#+id/txtnhap"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtnote"
android:layout_below="#+id/txtnote"
android:layout_marginTop="116dp"
android:ems="10"
android:hint="#string/hint_txt" >
<requestFocus />
</EditText>
<Spinner
android:id="#+id/menungonngu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/txtnhap"
android:layout_below="#+id/txtnote"
android:layout_marginTop="34dp" />
</RelativeLayout>
Can someone please help me fix code if you can?
Thanks so much!

how to switch from a fragment in a fragmentActivity to the Activity in android

I have a fragment class in with I am having few fragment tabs. each of them are opening another dedicated fragment. but I want to change one fragment to open an activity class. I have gone through many examples but didn't the problem solve. everytime my application goes crashed.
here is my fragment class.
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import org.apache.http.NameValuePair;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.graphics.Bitmap;
import android.graphics.Color;
import android.graphics.Typeface;
import android.os.AsyncTask;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.v4.app.Fragment;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.text.Editable;
import android.text.TextWatcher;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import com.appdupe.flamer.LoginUsingFacebook;
import com.appdupe.flamer.LoginUsingFacebook.BackGroundTaskForFetchingDataFromFaceBook;
import com.actionbarsherlock.app.SherlockFragmentActivity;
import com.androidquery.AQuery;
import com.androidquery.callback.ImageOptions;
import com.appdupe.androidpushnotifications.ChatActivity;
import com.appdupe.flamer.QuestionsActivity;
import com.appdupe.flamer.pojo.LikeMatcheddataForListview;
import com.appdupe.flamer.pojo.LikedMatcheData;
import com.appdupe.flamer.pojo.Likes;
import com.appdupe.flamer.utility.AlertDialogManager;
import com.appdupe.flamer.utility.AppLog;
import com.appdupe.flamer.utility.ConnectionDetector;
import com.appdupe.flamer.utility.Constant;
import com.appdupe.flamer.utility.ScalingUtilities;
import com.appdupe.flamer.utility.ScalingUtilities.ScalingLogic;
import com.appdupe.flamer.utility.SessionManager;
import com.appdupe.flamer.utility.Ultilities;
import com.appdupe.flamer.utility.Utility;
import com.appdupe.flamerchat.db.DatabaseHandler;
import com.appdupe.flamernofb.R;
import com.google.gson.Gson;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu;
import com.jeremyfeinstein.slidingmenu.lib.SlidingMenu.OnOpenListener;
public class MainActivity extends SherlockFragmentActivity implements
OnClickListener, OnOpenListener {
// MainLayout mLayout;
private static final String TAG = "MainActivity";
private ListView matcheslistview;
Button btMenu;
private Button buttonRightMenu;
TextView tvTitle;
private Typeface topbartextviewFont;
private Editor editor;
private SharedPreferences preferences;
private EditText etSerchFriend;
double mLatitude = 0;
double mLongitude = 0;
double dLatitude = 0;
double dLongitude = 0;
// private Session.StatusCallback statusCallback = new
// SessionStatusCallback();
private Dialog mdialog;
// private boolean usersignup = false;
private boolean isProfileclicked = false;
private ArrayList<LikeMatcheddataForListview> arryList;
private MatchedDataAdapter adapter;
private ImageView profileimage;
private LinearLayout profilelayout, homelayout, messages, settinglayout,
invitelayout, questionLayout;
public SlidingMenu menu;
private boolean flagforHome, flagForProfile, flagForsetting;
// private AQuery aQuery;
private ImageOptions options;
private ConnectionDetector cd;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// mLayout = (MainLayout)
// this.getLayoutInflater().inflate(R.layout.slidmenuxamplemainactivity,
// null);
// setContentView(mLayout);
cd = new ConnectionDetector(this);
preferences = PreferenceManager.getDefaultSharedPreferences(this);
editor = preferences.edit();
// aQuery = new AQuery(this);
options = new ImageOptions();
options.fileCache = true;
options.memCache = true;
setContentView(R.layout.slidmenuxamplemainactivity);
if (preferences.getBoolean(Constant.PREF_ISFIRST, true)) {
editor.putBoolean(Constant.PREF_ISFIRST, false);
editor.commit();
//startActivity(new Intent(this, QuestionsActivity.class));
}
tvTitle = (TextView) findViewById(R.id.activity_main_content_title);
topbartextviewFont = Typeface.createFromAsset(getAssets(),
"fonts/HelveticaLTStd-Light.otf");
tvTitle.setTypeface(topbartextviewFont);
tvTitle.setTextColor(Color.rgb(255, 255, 255));
tvTitle.setTextSize(20);
menu = new SlidingMenu(this);
menu.setMode(SlidingMenu.LEFT_RIGHT);
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_MARGIN);
menu.setShadowWidthRes(R.dimen.shadow_width);
menu.setShadowDrawable(R.drawable.shadow);
menu.setBehindOffsetRes(R.dimen.slidingmenu_offset);
menu.setFadeDegree(0.35f);
menu.attachToActivity(this, SlidingMenu.SLIDING_CONTENT);
Log.d(TAG, "onCreate before add menu ");
menu.setMenu(R.layout.leftmenu);
menu.setSecondaryMenu(R.layout.rightmenu);
Log.d(TAG, "onCreate add menu ");
menu.setSlidingEnabled(true);
Log.d(TAG, "onCreate finish");
// search
etSerchFriend = (EditText) menu
.findViewById(R.id.et_serch_right_side_menu);
// btnSerch = (Button) menu.findViewById(R.id.btn_serch_right_side);
View leftmenuview = menu.getMenu();
View rightmenuview = menu.getSecondaryMenu();
initLayoutComponent(leftmenuview, rightmenuview);
menu.setSecondaryOnOpenListner(this);
// lvMenuItems = getResources().getStringArray(R.array.menu_items);
// lvMenu.setAdapter(new
// ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,
// lvMenuItems));
matcheslistview.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
long arg3) {
// logDebug("setOnItemClickListener onItemClick arg2 "+arg2);
LikeMatcheddataForListview matcheddataForListview = (LikeMatcheddataForListview) arg0
.getItemAtPosition(arg2);
String faceboolid = matcheddataForListview.getFacebookid();
// logDebug(" background setOnItemClickListener onItemClick friend facebook id faceboolid "+faceboolid);
// logDebug(" background setOnItemClickListener onItemClick user facebook id faceboolid"+new
// SessionManager(MainActivity.this).getFacebookId());
Bundle mBundle = new Bundle();
mBundle.putString(Constant.FRIENDFACEBOOKID, faceboolid);
mBundle.putString(Constant.CHECK_FOR_PUSH_OR_NOT, "1");
Intent mIntent = new Intent(MainActivity.this,
ChatActivity.class);
mIntent.putExtras(mBundle);
startActivity(mIntent);
menu.toggle();
}
});
buttonRightMenu = (Button) findViewById(R.id.button_right_menu);
btMenu = (Button) findViewById(R.id.button_menu);
btMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// Show/hide the menu
toggleMenu(v);
}
});
try {
profilelayout.setOnClickListener(this);
homelayout.setOnClickListener(this);
messages.setOnClickListener(this);
settinglayout.setOnClickListener(this);
invitelayout.setOnClickListener(this);
questionLayout.setOnClickListener(this);
} catch (Exception e) {
AppLog.handleException("oncreate Exception ", e);
}
// Bundle extras = getIntent().getExtras();
System.out.println("Get Intent done");
try {
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
FindMatches fragment = new FindMatches();
ft.add(R.id.activity_main_content_fragment, fragment);
tvTitle.setText(getResources().getString(R.string.app_name));
ft.commit();
setProfilePick(profileimage);
} catch (Exception e) {
AppLog.handleException("onCreate Exception ", e);
}
Ultilities mUltilities = new Ultilities();
int imageHeightAndWidht[] = mUltilities
.getImageHeightAndWidthForAlubumListview(this);
arryList = new ArrayList<LikeMatcheddataForListview>();
adapter = new MatchedDataAdapter(this, arryList, imageHeightAndWidht);
matcheslistview.setAdapter(adapter);
// final SessionManager sessionManager = new SessionManager(this);
buttonRightMenu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (isProfileclicked) {
Intent mIntent = new Intent(MainActivity.this,
EditProfileNew.class);
startActivity(mIntent);
} else {
toggleRightMenu(v);
}
}
});
initSerchData();
}
private void initSerchData() {
etSerchFriend.addTextChangedListener(new TextWatcher() {
#Override
public void onTextChanged(CharSequence s, int start, int before,
int count) {
adapter.getFilter().filter(s.toString().trim());
}
#Override
public void beforeTextChanged(CharSequence s, int start, int count,
int after) {
}
#Override
public void afterTextChanged(Editable s) {
}
});
}
public void setMenuTouchFullScreenEnable(boolean isEnable) {
if (isEnable) {
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_FULLSCREEN);
} else {
menu.setTouchModeAbove(SlidingMenu.TOUCHMODE_NONE);
}
}
#Override
public void onOpen() {
AppLog.Log(TAG, "onOpen");
findLikedMatched();
}
#Override
protected void onResume() {
super.onResume();
AppLog.Log(TAG, " MainActivity onResume called");
}
private void setProfilePick(final ImageView userProfilImage) {
final Ultilities mUltilities = new Ultilities();
new Thread(new Runnable() {
#Override
public void run() {
final Bitmap bitmapimage = Utility.getBitmapFromURL(preferences
.getString(Constant.PREF_PROFILE_IMAGE_ONE, ""));
runOnUiThread(new Runnable() {
#Override
public void run() {
AppLog.Log(
TAG,
"Profile Image Url:"
+ preferences
.getString(
Constant.PREF_PROFILE_IMAGE_ONE,
""));
Bitmap cropedBitmap = null;
ScalingUtilities mScalingUtilities = new ScalingUtilities();
Bitmap mBitmap = null;
if (bitmapimage != null) {
cropedBitmap = mScalingUtilities
.createScaledBitmap(bitmapimage, 80, 80,
ScalingLogic.CROP);
bitmapimage.recycle();
mBitmap = mUltilities.getCircleBitmap(cropedBitmap,
1);
cropedBitmap.recycle();
userProfilImage.setImageBitmap(mBitmap);
// aQuery.id(userProfilImage).image(mBitmap);
} else {
}
}
});
}
}).start();
}
private void initLayoutComponent(View leftmenu, View rightmenu) {
matcheslistview = (ListView) rightmenu
.findViewById(R.id.menu_right_ListView);
profileimage = (ImageView) leftmenu.findViewById(R.id.profileimage);
profilelayout = (LinearLayout) leftmenu
.findViewById(R.id.profilelayout);
homelayout = (LinearLayout) leftmenu.findViewById(R.id.homelayout);
messages = (LinearLayout) leftmenu.findViewById(R.id.messages);
settinglayout = (LinearLayout) leftmenu
.findViewById(R.id.settinglayout);
invitelayout = (LinearLayout) leftmenu.findViewById(R.id.invitelayout);
/*questionLayout = (LinearLayout) leftmenu
.findViewById(R.id.questionLayout);*///devraj
}
private void findLikedMatched() {
AppLog.Log(TAG, "findLikedMatched");
String params[] = { preferences.getString(Constant.FACEBOOK_ID, "") };
new BackgroundTaskForFindLikeMatched().execute(params);
}
private class BackgroundTaskForFindLikeMatched extends
AsyncTask<String, Void, Void> {
private Ultilities mUltilities = new Ultilities();
private List<NameValuePair> getuserparameter;
private String likedmatchedata;
private LikedMatcheData matcheData;
private ArrayList<Likes> likesList;
private LikeMatcheddataForListview matcheddataForListview;
DatabaseHandler mDatabaseHandler = new DatabaseHandler(
MainActivity.this);
private boolean isResponseSuccess = true;
#Override
protected Void doInBackground(String... params) {
try {
File appDirectory = mUltilities
.createAppDirectoy(getResources().getString(
R.string.appdirectory));
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground appDirectory "
+ appDirectory);
File _picDir = new File(appDirectory, getResources().getString(
R.string.imagedirematchuserdirectory));
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground ");
getuserparameter = mUltilities.getUserLikedParameter(params);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground getuserparameter "
+ getuserparameter);
likedmatchedata = mUltilities.makeHttpRequest(
Constant.getliked_url, Constant.methodeName,
getuserparameter);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likedmatchedata "
+ likedmatchedata);
Gson gson = new Gson();
matcheData = gson.fromJson(likedmatchedata,
LikedMatcheData.class);
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground matcheData "
+ matcheData);
if (matcheData.getErrFlag() == 0) {
likesList = matcheData.getLikes();
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likesList "
+ likesList);
if (arryList != null) {
arryList.clear();
}
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched doInBackground likesList sized "
+ likesList.size());
for (int i = 0; i < likesList.size(); i++) {
matcheddataForListview = new LikeMatcheddataForListview();
String userName = likesList.get(i).getfName();
String facebookid = likesList.get(i).getFbId();
String picturl = likesList.get(i).getpPic();
int falg = likesList.get(i).getFlag();
String latd = likesList.get(i).getLadt();
matcheddataForListview.setFacebookid(facebookid);
matcheddataForListview.setUserName(userName);
matcheddataForListview.setImageUrl(picturl);
matcheddataForListview.setFlag("" + falg);
matcheddataForListview.setladt(latd);
File imageFile = mUltilities.createFileInSideDirectory(
_picDir, userName + facebookid + ".jpg");
Utility.addBitmapToSdCardFromURL(likesList.get(i)
.getpPic().replaceAll(" ", "%20"), imageFile);
matcheddataForListview.setFilePath(imageFile
.getAbsolutePath());
if (!preferences.getString(Constant.FACEBOOK_ID, "")
.equals(facebookid)) {
arryList.add(matcheddataForListview);
}
}
DatabaseHandler mDatabaseHandler = new DatabaseHandler(
MainActivity.this);
ArrayList<LikeMatcheddataForListview> arryListtem = mDatabaseHandler
.getUserFindMatch();
AppLog.Log(TAG, "arryListtem " + arryListtem);
if (arryListtem != null && arryListtem.size() > 0) {
AppLog.Log(TAG, "arryList size " + arryListtem.size());
arryList.clear();
arryList.addAll(arryListtem);
mUltilities.showImage
}
}
// "errNum": "50",
// "errFlag": "1",
// "errMsg": "Sorry, no matches found!"
else if (matcheData.getErrFlag() == 1) {
ArrayList<LikeMatcheddataForListview> arryListtem = mDatabaseHandler
.getUserFindMatch();
AppLog.Log(TAG, "arryListtem " + arryListtem);
if (arryListtem != null && arryListtem.size() > 0) {
AppLog.Log(TAG, "arryList size " + arryListtem.size());
arryList.clear();
arryList.addAll(arryListtem);
}
} else {
}
} catch (Exception e) {
AppLog.handleException(
"BackgroundTaskForFindLikeMatched doInBackground Exception ",
e);
isResponseSuccess = false;
}
return null;
}
#Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
AppLog.Log(TAG, "BackgroundTaskForFindLikeMatched onPostExecute ");
try {
mdialog.dismiss();
} catch (Exception e) {
AppLog.Log(TAG,
"BackgroundTaskForFindLikeMatched onPostExecute Exception "
+ e);
}
if (!isResponseSuccess) {
AlertDialogManager.errorMessage(MainActivity.this, "Alert",
"Request timeout");
}
adapter.notifyDataSetChanged();
}
#Override
protected void onPreExecute() {
super.onPreExecute();
AppLog.Log(TAG, "BackgroundTaskForFindLikeMatched onPreExecute ");
try {
mdialog = mUltilities.GetProcessDialog(MainActivity.this);
mdialog.setCancelable(false);
mdialog.show();
} catch (Exception e) {
AppLog.handleException(
"BackgroundTaskForFindLikeMatched onPreExecute Exception ",
e);
}
}
}
private class MatchedDataAdapter extends
ArrayAdapter<LikeMatcheddataForListview> {
private AQuery aQuery;
private Activity mActivity;
private LayoutInflater mInflater;
private SessionManager sessionManager;
public MatchedDataAdapter(Activity context,
List<LikeMatcheddataForListview> objects,
int imageHeigthAndWidth[]) {
super(context, R.layout.matchedlistviewitem, objects);
mActivity = context;
mInflater = (LayoutInflater) mActivity
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
// this.imageHeigthAndWidth=imageHeigthAndWidth;
sessionManager = new SessionManager(context);
aQuery = new AQuery(context);
}
#Override
public int getCount() {
return super.getCount();
}
#Override
public LikeMatcheddataForListview getItem(int position) {
return super.getItem(position);
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ViewHolder holder;
if (convertView == null) {
holder = new ViewHolder();
convertView = mInflater.inflate(R.layout.matchedlistviewitem,
null);
holder.imageview = (ImageView) convertView
.findViewById(R.id.userimage);
holder.textview = (TextView) convertView
.findViewById(R.id.userName);
holder.lastMasage = (TextView) convertView
.findViewById(R.id.lastmessage);
convertView.setTag(holder);
} else {
holder = (ViewHolder) convertView.getTag();
}
holder.textview.setId(position);
holder.imageview.setId(position);
holder.lastMasage.setId(position);
holder.textview.setText(getItem(position).getUserName());
aQuery.id(holder.imageview).image(getItem(position).getImageUrl());
try {
holder.lastMasage.setText(sessionManager
.getLastMessage(getItem(position).getFacebookid()));
} catch (Exception e) {
AppLog.handleException(TAG + " getView Exception ", e);
}
return convertView;
}
class ViewHolder {
ImageView imageview;
TextView textview;
TextView lastMasage;
}
}
public void toggleMenu(View v) {
menu.toggle();
}
public void toggleRightMenu(View v) {
menu.showSecondaryMenu();
}
#Override
public void onBackPressed() {
if (menu.isMenuShowing()) {
menu.toggle();
} else if (menu.isSecondaryMenuShowing()) {
menu.showSecondaryMenu();
} else {
super.onBackPressed();
}
}
#Override
public void onStop() {
super.onStop();
if (mdialog != null) {
mdialog.dismiss();
mdialog = null;
}
}
#Override
protected void onDestroy() {
if (mdialog != null && mdialog.isShowing()) {
mdialog.dismiss();
}
super.onDestroy();
}
#Override
public void onClick(View v) {
FragmentManager fm = MainActivity.this.getSupportFragmentManager();
FragmentTransaction ft = fm.beginTransaction();
Fragment fragment = null;
if (v.getId() == R.id.homelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagforHome) {
menu.toggle();
return;
} else {
fragment = new FindMatches();
buttonRightMenu
.setBackgroundResource(R.drawable.selector_for_message_button);
tvTitle.setText(getResources().getString(R.string.app_name));
flagforHome = true;
flagForProfile = false;
flagForsetting = false;
isProfileclicked = false;
if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
}
menu.toggle();
}
} else if (v.getId() == R.id.profilelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagForProfile) {
menu.toggle();
return;
} else {
buttonRightMenu.setBackgroundResource(R.drawable.edit_btn);
isProfileclicked = true;
fragment = new UserProfile();
tvTitle.setText(getResources().getString(R.string.myprofile));
flagforHome = false;
flagForProfile = true;
flagForsetting = false;
if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
}
menu.toggle();
}
}
else if (v.getId() == R.id.settinglayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
if (flagForsetting) {
menu.toggle();
return;
} else {
buttonRightMenu
.setBackgroundResource(R.drawable.selector_for_message_button);
tvTitle.setText(getResources().getString(R.string.settings));
fragment = new SettingActivity();
flagforHome = false;
flagForProfile = false;
flagForsetting = true;
flagForInvite=false;
isProfileclicked = false;
/*if (fragment != null) {
ft.replace(R.id.activity_main_content_fragment, fragment);
ft.commit();
// tvTitle.setText(selectedItem);
}*/
menu.toggle();
/*Intent setIntent = new Intent(getApplicationContext(),Setting2.class);
startActivity(setIntent);*/
}
}
///devraj
else if (v.getId() == R.id.messages) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
toggleRightMenu(v);
} /*else if (v.getId() == R.id.questionLayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;*/
/*}
menu.toggle();
Intent questionIntent = new Intent(this, QuestionsActivity.class);
startActivity(questionIntent);*/
//}
else if (v.getId() == R.id.invitelayout) {
if (!cd.isConnectingToInternet()) {
Toast.makeText(this, "No Internet", Toast.LENGTH_SHORT).show();
return;
}
// Change by Dilavar
Intent sendIntent = new Intent();
sendIntent.setAction(Intent.ACTION_SEND);
sendIntent
.putExtra(
Intent.EXTRA_TEXT,
"I am using Flamer App ! Why don't you try it out...\nInstall Flamer now !\nhttps://play.google.com/store/apps/details?id=com.appdupe.flamernofb");
sendIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,
" Flamer App !");
sendIntent.setType("message/rfc822"); //
sendIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[] { " info#appdupe.com" });
startActivity(Intent
.createChooser(sendIntent, "Send mail using..."));
}
/*settinglayout.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent mintent = new Intent(getApplicationContext(),Setting2.class);
startActivity(mintent);
}
});*/
}
}
I want Setting tab to open a new activity not fragment that is Setting2
here is my activity class that I have to open
import android.app.Activity;
import android.os.Bundle;
public class Setting2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.setting2);
}
}
Here is my layout , I am posting it here as it so long and don't have permission to post more lines in question.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#088A08" >
<Button
android:id="#+id/button_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:background="#drawable/selector_for_menu_button"
android:onClick="toggleMenu" />
<TextView
android:id="#+id/activity_main_content_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Toker" />
<Button
android:id="#+id/button_right_menu"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="10dp"
android:background="#drawable/selector_for_message_button"
android:onClick="rightmenu" />
</RelativeLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="#088A08" >
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:background="#088A08" >
<ImageView
android:id="#+id/imagev1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/btn_add_photo"
android:gravity="center_horizontal" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout1"
android:layout_centerHorizontal="true"
android:layout_marginTop="22dp"
android:background="#088A08"
android:gravity="center_horizontal"
android:text="View My Profile" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="5.0">
<RelativeLayout
android:id="#+id/lin1"
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:background="#ffffff"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignTop="#+id/imageView1"
android:layout_marginBottom="9dp"
android:layout_marginLeft="21dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Discovery Settings"
android:textSize="12dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_alignLeft="#+id/textView1"
android:text="Change who you see" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/pref" />
<Button
android:id="#+id/morebtn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView1"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/settings" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/imageView2"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/imageView2"
android:text="App Settings"
android:textSize="12dp" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView2"
android:layout_alignLeft="#+id/textView3"
android:text="Notification and Resource" />
<Button
android:id="#+id/morebtn2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView3"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/filter" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView3"
android:layout_marginLeft="23dp"
android:layout_toRightOf="#+id/imageView3"
android:text="What are you into" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_alignTop="#+id/imageView3"
android:text="Your Interest"
android:textSize="12dp" />
<Button
android:id="#+id/morebtn3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView8"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/reachout" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView5"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/imageView5"
android:text="We want to hear it all" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView6"
android:layout_alignTop="#+id/imageView5"
android:text="Get in Touch"
android:textSize="12dp" />
<Button
android:id="#+id/morebtn4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView7"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_weight="1.0"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:layout_marginLeft="12dp"
android:background="#drawable/share" />
<Button
android:id="#+id/morebtn5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/textView5"
android:layout_marginRight="20dp"
android:background="#drawable/more" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/morebtn5"
android:layout_marginLeft="27dp"
android:layout_toRightOf="#+id/imageView4"
android:text="Help us spread the world" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView9"
android:layout_alignTop="#+id/imageView4"
android:text="Tell Your Friends"
android:textSize="12dp" />
</RelativeLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#color/black"
android:orientation="horizontal"/>
</LinearLayout>
</LinearLayout>
Step 1
- declare your activity inside of the manifest
Step 2
- starActivity(new Intent(getAcivity(), MyClass.class));
Step 3
- post your logcat if this didn't help while it should !
Edit: the issue seems that you are not setting a height to your layouts, base on your layout that you posted you have five layouts that are missing android:layout_height please add that and force close shall be gone.

[Android]: Navigation Drawer How to create something like this?

How do I get the line in sync with the round ball images and how to change the text and image when clicked ?
I'd like to do something like this:
https://www.behance.net/gallery/13564677/Blog
I got the ListView but I just need help in building the straight line pass through the round ball images.
Thanks for your help!
My Code Follows:
My activity_main.xml
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/drawerlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#d3d3d3"
>
<FrameLayout
android:id="#+id/mainContent"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
</FrameLayout>
<ListView
android:id="#+id/drawerList"
android:layout_width="240dp"
android:layout_height="match_parent"
android:divider="#null"
android:layout_gravity="left"
android:background="#A55676"
>
</ListView>
</android.support.v4.widget.DrawerLayout>
custom_row.xml
?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:paddingLeft="35dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="10dp"
android:orientation="horizontal"
android:background="#drawable/border"
>
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="-5sp"
android:paddingTop="30dp"
/>
<TextView
android:id="#+id/textView1"
android:layout_width="90dp"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="25dp"
android:drawablePadding="20dp"
android:paddingLeft="3dp"
android:paddingTop="25dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#ffffff" />
</LinearLayout>
</LinearLayout>
MainActivity.java
import android.support.v4.app.ActionBarDrawerToggle;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarActivity;
import android.content.Context;
import android.content.Intent;
import android.content.res.Configuration;
import android.graphics.Typeface;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends ActionBarActivity implements OnItemClickListener {
private DrawerLayout drawerLayout;
private ListView listview;
private ActionBarDrawerToggle drawerListener;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
listview=(ListView) findViewById(R.id.drawerList);
drawerLayout=(DrawerLayout)findViewById(R.id.drawerlayout);
MyAdapter myAdapter = new MyAdapter(this);
listview.setAdapter(myAdapter);
drawerLayout.setDrawerShadow(R.drawable.navbar_shadow, Gravity.LEFT);
drawerListener = new ActionBarDrawerToggle(this, drawerLayout,R.drawable.ic_drawer,R.string.drawer_open, R.string.drawer_close)
{
#Override
public void onDrawerClosed(View drawerView)
{
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"Drawer Closed", Toast.LENGTH_LONG).show();
}
#Override
public void onDrawerOpened(View drawerView) {
// TODO Auto-generated method stub
Toast.makeText(MainActivity.this,"Drawer Opened", Toast.LENGTH_LONG).show();
}
};
drawerLayout.setDrawerListener(drawerListener);
getActionBar().setHomeButtonEnabled(true);
getActionBar().setDisplayHomeAsUpEnabled(true);
getActionBar().setDisplayShowTitleEnabled(false);
getActionBar().setIcon(R.color.transparent);
listview.setOnItemClickListener(this);
}
#Override
protected void onPostCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onPostCreate(savedInstanceState);
drawerListener.syncState();
}
#Override
public void onConfigurationChanged(Configuration newConfig) {
// TODO Auto-generated method stub
super.onConfigurationChanged(newConfig);
drawerListener.onConfigurationChanged(newConfig);
}
public void selectItem(int position)
{// TODO Auto-generated method stub
listview.setItemChecked(position, true);
//setTitle(planets[position]);
}
public void setTitle(String title)
{
getActionBar().setTitle(title);
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
if(drawerListener.onOptionsItemSelected(item))
{
return true;
}
return super.onOptionsItemSelected(item);
}
#Override
public void onItemClick(AdapterView<?> parent, View view, int position,
long id)
{ // TODO Auto-generated method stub
ImageView titleImageView = (ImageView)view.findViewById(R.id.imageView1);
TextView titleTextView = (TextView)view.findViewById(R.id.textView1);
switch(position)
{
case 0:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState()){
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
break;
case 1:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState())
{
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
break;
case 2:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState())
{
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
break;
case 3:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState())
{
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
Intent intent = new Intent(getApplicationContext(),Featured.class);
startActivity(intent);
break;
case 4:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState())
{
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
break;
case 5:
if (titleImageView.getDrawable().getConstantState() == getResources().getDrawable( R.drawable.ic_new).getConstantState())
{
titleImageView.setImageResource(R.drawable.ic_new1);
titleTextView.setTypeface(Typeface.DEFAULT_BOLD);
}
else
{
titleImageView.setImageResource(R.drawable.ic_new);
titleTextView.setTextAppearance(getApplicationContext(), R.style.normalText);
}
break;
default:
break;
}
}
}
class MyAdapter extends BaseAdapter
{
String[] socialSites;
int [] images = {R.drawable.ic_new,R.drawable.ic_new,R.drawable.ic_new,R.drawable.ic_new,R.drawable.ic_new,R.drawable.ic_new};
Context context;
public MyAdapter(Context context) {
// TODO Auto-generated constructor stub
this.context=context;
socialSites = context.getResources().getStringArray(R.array.social);
}
#Override
public int getCount() {
// TODO Auto-generated method stub
return socialSites.length;
}
#Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return socialSites[position];
}
#Override
public long getItemId(int position) {
// TODO Auto-generated method stub
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
View row = null;
if(convertView == null)
{
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
row = inflater.inflate(R.layout.custom_row,parent, false);
}
else
{
row=convertView;
}
TextView titleTextView = (TextView) row.findViewById(R.id.textView1);
ImageView titleImageView = (ImageView) row.findViewById(R.id.imageView1);
titleTextView.setText(socialSites[position]);
titleImageView.setImageResource(images[position]);
return row;
}
}
Use a ListView, and assign a 9-patch drawable to each item's background which will consist of a centered dot and the vertical line.
The whole trick will be to specify the strechable regions of your nine-patch properly (stretch the line and not the dot).
Once you are happy with that, just make a different dot appearance for the active element and use an XML selector drawable to assign either the default or activated state 9 patch to the background.

ImageView is not clickeble?

I am using Imageview 2 times in my MainActivity.java class by using LayoutInflater.In that activity i am inflate so many layouts by using scroll every thing works fine.But this imageview is not working properly.When user click on imageview it shows popup.It works when i am show first time inflate.It's not working second time inflate.
In my main activity contain edittext.when user enter High in edittext i want to show 2 imageview times.If user enter Low i want to show single imageview.One imageview shows top of the screen and one shows bottom of the screen.
Here my bit of code.
This is my imageview.xml:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/attach_photo_layout"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_margin="10dp" >
<TextView
android:id="#+id/attach_photo_titile_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="5dp"
android:text="#string/attach_photo_to_job"
android:textColor="#android:color/white" />
<ImageView
android:id="#+id/attach_photo_camera_ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/attach_photo_titile_textView"
android:contentDescription="#string/app_name"
android:clickable="true"
android:src="#drawable/image_placeholder" />
</RelativeLayout>
I am using this layout in my main.xml by using .
And i am call that imageview.xml layout in My MainActivity.java by using LayoutInflater.
Here is my code:
public void getAudioRecordLayout() {
testView = testInflater.inflate(
getResources().getLayout(
R.layout.imageview), null);
mWorkDetailAttachImageView = (ImageView) findViewById(R.id.attach_photo_camera_ImageView);
mIncludeHighLayout = (LinearLayout) findViewById(R.id.include_High);
mIncludeLowLayout = (LinearLayout) findViewById(R.id.include_Low);
mIncludeRecordAudioInWorkDetailLayout.setVisibility(View.VISIBLE);
mIncludeRecordAudioInRecordOfInspectionLayout
.setVisibility(View.GONE);
mWorkDetailAttachImageView.setOnClickListener(this);
}
Edit # 1 :
When i am showing imageview second time that imageview shows inside another inflate view.
Image view OnclickListiener :
if (v == mWorkDetailAttachImageView) {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.add_picture_image_dialog,
null);
final AlertDialog alertDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(
TestResultsActivity.this);
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setCancelable(true);
alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.show();
Button cancel = (Button) view
.findViewById(R.id.cancel_img_dialog_btn);
Button takeNew = (Button) view
.findViewById(R.id.take_new_photo_btn);
Button chooseExisting = (Button) view
.findViewById(R.id.choose_from_existing_img_btn);
takeNew.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
alertDialog.dismiss();
}
});
chooseExisting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
}
Edit # 2
MainActivity.java
package rajesh.dropdowndemo;
import java.security.PublicKey;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.Intent;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Layout holding the droddown view */
private LinearLayout mDropdownFoldOutMenu;
/** Textview holding the title of the droddown */
private TextView mDropdownTitle;
ImageView imagView;
LinearLayout commonIncludeLayout, includeHighLayout;
int i = 1;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getImageViewLayout(1);
getImageViewLayout(2);
// getHighLayout();
mDropdownFoldOutMenu = ((LinearLayout) findViewById(R.id.dropdown_foldout_menu));
mDropdownTitle = ((TextView) findViewById(R.id.dropdown_textview));
commonIncludeLayout = (LinearLayout) findViewById(R.id.include_imageview_layout);
includeHighLayout = (LinearLayout) findViewById(R.id.include_high_imageview_layout);
final TextView dropDownTextView = (TextView) findViewById(R.id.dropdown_textview);
final TextView alt0 = (TextView) findViewById(R.id.dropdown_alt0);
final TextView alt1 = (TextView) findViewById(R.id.dropdown_alt1);
final TextView alt2 = (TextView) findViewById(R.id.dropdown_alt2);
dropDownTextView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
if (mDropdownFoldOutMenu.getVisibility() == View.GONE) {
openDropdown();
} else {
closeDropdown();
}
}
});
alt0.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.VISIBLE);
dropDownTextView.setText(R.string.alt0);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
Toast.makeText(getBaseContext(), R.string.alt0,
Toast.LENGTH_SHORT).show();
}
});
alt1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.GONE);
dropDownTextView.setText(R.string.alt1);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
Toast.makeText(getBaseContext(), R.string.alt1,
Toast.LENGTH_SHORT).show();
}
});
alt2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.GONE);
dropDownTextView.setText(R.string.alt2);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
Toast.makeText(getBaseContext(), R.string.alt2,
Toast.LENGTH_SHORT).show();
}
});
}
/**
* Animates in the dropdown list
*/
private void openDropdown() {
if (mDropdownFoldOutMenu.getVisibility() != View.VISIBLE) {
ScaleAnimation anim = new ScaleAnimation(1, 1, 0, 1);
anim.setDuration(getResources().getInteger(
R.integer.dropdown_amination_time));
mDropdownFoldOutMenu.startAnimation(anim);
mDropdownTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_close, 0);
mDropdownFoldOutMenu.setVisibility(View.VISIBLE);
}
}
/**
* Animates out the dropdown list
*/
private void closeDropdown() {
if (mDropdownFoldOutMenu.getVisibility() == View.VISIBLE) {
ScaleAnimation anim = new ScaleAnimation(1, 1, 1, 0);
anim.setDuration(getResources().getInteger(
R.integer.dropdown_amination_time));
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
mDropdownFoldOutMenu.setVisibility(View.GONE);
}
});
mDropdownTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_open, 0);
mDropdownFoldOutMenu.startAnimation(anim);
}
}
/**
*
* This represents Inflate the layout into main.xml layout
*/
public void getImageViewLayout(final int aa) {
// LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
// View view = inflater.inflate(R.layout.imageview, null);
RelativeLayout outer;
if (aa == 1)
outer = (RelativeLayout) findViewById(R.id.image_layout);
else
outer = (RelativeLayout) findViewById(R.id.image_layout1);
imagView = (ImageView) outer
.findViewById(R.id.attach_photo_camera_ImageView);
imagView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Imageview Clicked");
if (aa == 1)
imagView.setTag(1);
else
imagView.setTag(2);
LayoutInflater inflater = LayoutInflater
.from(MainActivity.this);
View view = inflater.inflate(R.layout.add_picture_image_dialog,
null);
final AlertDialog alertDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setCancelable(true);
alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.show();
Button cancel = (Button) view
.findViewById(R.id.cancel_img_dialog_btn);
Button takeNew = (Button) view
.findViewById(R.id.take_new_photo_btn);
Button chooseExisting = (Button) view
.findViewById(R.id.choose_from_existing_img_btn);
takeNew.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, 100);
alertDialog.dismiss();
}
});
chooseExisting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, 200);
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == 100 && resultCode == RESULT_OK && null != data) {
// get Image
Bitmap thumbnail = (Bitmap) data.getExtras().get("data");
System.out.println(imagView.getTag().toString());
String i = imagView.getTag().toString();
if (imagView.getTag(1) == i)
((ImageView) imagView.getTag(1)).setImageBitmap(thumbnail);
else if(imagView.getTag(2) != null)
((ImageView) imagView.getTag(2)).setImageBitmap(thumbnail);
} else if (resultCode == RESULT_CANCELED) {
System.out.println(imagView.getTag());
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT)
.show();
}
if (requestCode == 200 && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
Bitmap bit = (Bitmap) BitmapFactory.decodeFile(picturePath);
System.out.println(imagView.getTag().toString());
String i = imagView.getTag().toString();
if (imagView.getTag() == i)
((ImageView) imagView.getTag(1)).setImageBitmap(bit);
else if(imagView.getTag(2) != null)
((ImageView) imagView.getTag(2)).setImageBitmap(bit);
} else if (resultCode == RESULT_CANCELED) {
Toast.makeText(this, "Picture was not taken", Toast.LENGTH_SHORT)
.show();
}
}
}
main.xml
<?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="match_parent"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="#+id/dropdown_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_background"
android:drawableRight="#drawable/icn_dropdown_open"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="Dropdown alts:" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dropdown_textview"
android:layout_marginTop="10dip"
android:padding="100dip"
android:text="other content" />
<LinearLayout
android:id="#+id/include_imageview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:orientation="vertical">
<include layout="#layout/imageview"/>
</LinearLayout>
<LinearLayout
android:id="#+id/dropdown_foldout_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dropdown_textview"
android:layout_marginTop="2dip"
android:background="#drawable/dropdown_background"
android:orientation="vertical"
android:padding="1dip"
android:visibility="gone" >
<TextView
android:id="#+id/dropdown_alt0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:drawableRight="#drawable/icn_dropdown_checked"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt0" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#cccccc" />
<TextView
android:id="#+id/dropdown_alt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt1" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#cccccc" />
<TextView
android:id="#+id/dropdown_alt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt2" />
</LinearLayout>
<LinearLayout
android:id="#+id/include_high_imageview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone">
<include layout="#layout/high_layout"/>
</LinearLayout>
</RelativeLayout>
imageview.xml
<?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="wrap_content"
android:orientation="vertical"
android:background="#android:color/background_dark" >
<TextView
android:id="#+id/attach_photo_titile_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:padding="5dp"
android:text="Attach Photo"
android:textColor="#android:color/white" />
<ImageView
android:id="#+id/attach_photo_camera_ImageView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/attach_photo_titile_textView"
android:contentDescription="#string/app_name"
android:clickable="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
dailog.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/take_new_photo_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="20dp"
android:text="Take New Photo" />
<Button
android:id="#+id/choose_from_existing_img_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="Choose Existing" />
<Button
android:id="#+id/cancel_img_dialog_btn"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="10dp"
android:text="Cancel" />
</LinearLayout>
string.xml
<resources>
<string name="app_name">DropDownDemo</string>
<string name="alt0">High</string>
<string name="alt1">Low</string>
<string name="alt2">General</string>
</resources>
high_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<include
layout="#layout/imageview"/>
</LinearLayout>
Please any one help me.
Try this..
testView = testInflater.inflate(getResources().getLayout(R.layout.imageview), null);
mWorkDetailAttachImageView = (ImageView) testView.findViewById(R.id.attach_photo_camera_ImageView);
add in your click
mWorkDetailAttachImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Button cancel = (Button) view
.findViewById(R.id.cancel_img_dialog_btn);
Button takeNew = (Button) view
.findViewById(R.id.take_new_photo_btn);
Button chooseExisting = (Button) view
.findViewById(R.id.choose_from_existing_img_btn);
takeNew.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
alertDialog.dismiss();
}
});
chooseExisting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
}
}
});
Or
if (v.getId() == R.id.attach_photo_camera_ImageView) {
LayoutInflater inflater = LayoutInflater.from(this);
View view = inflater.inflate(R.layout.add_picture_image_dialog,
null);
final AlertDialog alertDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(
TestResultsActivity.this);
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setCancelable(true);
alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.show();
Button cancel = (Button) view
.findViewById(R.id.cancel_img_dialog_btn);
Button takeNew = (Button) view
.findViewById(R.id.take_new_photo_btn);
Button chooseExisting = (Button) view
.findViewById(R.id.choose_from_existing_img_btn);
takeNew.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent cameraIntent = new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);
alertDialog.dismiss();
}
});
chooseExisting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent i = new Intent(
Intent.ACTION_PICK,
android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
startActivityForResult(i, RESULT_LOAD_IMAGE);
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
}
EDIT
LayoutInflater inflater = (LayoutInflater)getSystemService(Context.LAYOUT_INFLATER_SERVICE);
testView = inflater.inflate(R.layout.imageview, null);
EDIT 1
<?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="match_parent"
android:orientation="vertical"
android:padding="10dip" >
<TextView
android:id="#+id/dropdown_textview"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_background"
android:drawableRight="#drawable/icn_dropdown_open"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="Dropdown alts:" />
<Button
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dropdown_textview"
android:layout_marginTop="10dip"
android:padding="100dip"
android:text="other content" />
<LinearLayout
android:id="#+id/include_imageview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/button1"
android:orientation="vertical">
<include
android:id="#+id/image_layout"
layout="#layout/imageview"/>
</LinearLayout>
<LinearLayout
android:id="#+id/dropdown_foldout_menu"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/dropdown_textview"
android:layout_marginTop="2dip"
android:background="#drawable/dropdown_background"
android:orientation="vertical"
android:padding="1dip"
android:visibility="gone" >
<TextView
android:id="#+id/dropdown_alt0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:drawableRight="#drawable/icn_dropdown_checked"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt0" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#cccccc" />
<TextView
android:id="#+id/dropdown_alt1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt1" />
<View
android:layout_width="fill_parent"
android:layout_height="1dip"
android:background="#cccccc" />
<TextView
android:id="#+id/dropdown_alt2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dropdown_selector"
android:gravity="center_vertical|left"
android:padding="10dip"
android:text="#string/alt2" />
</LinearLayout>
<LinearLayout
android:id="#+id/include_high_imageview_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical"
android:visibility="gone">
<include
android:id="#+id/image_layout1"
layout="#layout/imageview"/>
</LinearLayout>
</RelativeLayout>
JAVA
package rajesh.dropdowndemo;
import android.app.Activity;
import android.app.AlertDialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.animation.Animation;
import android.view.animation.Animation.AnimationListener;
import android.view.animation.ScaleAnimation;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;
import android.widget.Toast;
public class MainActivity extends Activity {
/** Layout holding the droddown view */
private LinearLayout mDropdownFoldOutMenu;
/** Textview holding the title of the droddown */
private TextView mDropdownTitle;
LinearLayout commonIncludeLayout,includeHighLayout;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
getImageViewLayout(1);
getImageViewLayout(2);
mDropdownFoldOutMenu = ((LinearLayout) findViewById(R.id.dropdown_foldout_menu));
mDropdownTitle = ((TextView) findViewById(R.id.dropdown_textview));
commonIncludeLayout = (LinearLayout) findViewById(R.id.include_imageview_layout);
includeHighLayout = (LinearLayout) findViewById(R.id.include_high_imageview_layout);
final TextView dropDownTextView = (TextView) findViewById(R.id.dropdown_textview);
final TextView alt0 = (TextView) findViewById(R.id.dropdown_alt0);
final TextView alt1 = (TextView) findViewById(R.id.dropdown_alt1);
final TextView alt2 = (TextView) findViewById(R.id.dropdown_alt2);
dropDownTextView.setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
if (mDropdownFoldOutMenu.getVisibility() == View.GONE) {
openDropdown();
} else {
closeDropdown();
}
}
});
alt0.setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.VISIBLE);
dropDownTextView.setText(R.string.alt0);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
Toast.makeText(getBaseContext(), R.string.alt0, Toast.LENGTH_SHORT).show();
}
});
alt1.setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.GONE);
dropDownTextView.setText(R.string.alt1);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
Toast.makeText(getBaseContext(), R.string.alt1, Toast.LENGTH_SHORT).show();
}
});
alt2.setOnClickListener(
new OnClickListener() {
#Override
public void onClick(View v) {
includeHighLayout.setVisibility(View.GONE);
dropDownTextView.setText(R.string.alt2);
closeDropdown();
alt0.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt1.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);
alt2.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_checked, 0);
Toast.makeText(getBaseContext(), R.string.alt2, Toast.LENGTH_SHORT).show();
}
});
}
/**
* Animates in the dropdown list
*/
private void openDropdown() {
if (mDropdownFoldOutMenu.getVisibility() != View.VISIBLE) {
ScaleAnimation anim = new ScaleAnimation(1, 1, 0, 1);
anim.setDuration(getResources().getInteger(R.integer.dropdown_amination_time));
mDropdownFoldOutMenu.startAnimation(anim);
mDropdownTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_close, 0);
mDropdownFoldOutMenu.setVisibility(View.VISIBLE);
}
}
/**
* Animates out the dropdown list
*/
private void closeDropdown() {
if (mDropdownFoldOutMenu.getVisibility() == View.VISIBLE) {
ScaleAnimation anim = new ScaleAnimation(1, 1, 1, 0);
anim.setDuration(getResources().getInteger(R.integer.dropdown_amination_time));
anim.setAnimationListener(new AnimationListener() {
#Override
public void onAnimationStart(Animation animation) {
}
#Override
public void onAnimationRepeat(Animation animation) {
}
#Override
public void onAnimationEnd(Animation animation) {
mDropdownFoldOutMenu.setVisibility(View.GONE);
}
});
mDropdownTitle.setCompoundDrawablesWithIntrinsicBounds(0, 0,
R.drawable.icn_dropdown_open, 0);
mDropdownFoldOutMenu.startAnimation(anim);
}
}
/**
*
* This represents Inflate the layout into main.xml layout
*/
public void getImageViewLayout(int aa){
LinearLayout outer;
if(aa == 1)
outer = (LinearLayout) findViewById(R.id.image_layout);
else
outer = (LinearLayout) findViewById(R.id.image_layout1);
ImageView imagView = (ImageView) outer.findViewById(R.id.attach_photo_camera_ImageView);
imagView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
System.out.println("Imageview Clicked");
LayoutInflater inflater = LayoutInflater.from(MainActivity.this);
View view = inflater.inflate(R.layout.add_picture_image_dialog,
null);
final AlertDialog alertDialog;
AlertDialog.Builder builder = new AlertDialog.Builder(
MainActivity.this);
builder.setView(view);
builder.setInverseBackgroundForced(true);
builder.setCancelable(true);
alertDialog = builder.create();
alertDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
alertDialog.show();
Button cancel = (Button) view
.findViewById(R.id.cancel_img_dialog_btn);
Button takeNew = (Button) view
.findViewById(R.id.take_new_photo_btn);
Button chooseExisting = (Button) view
.findViewById(R.id.choose_from_existing_img_btn);
takeNew.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
chooseExisting.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
cancel.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
alertDialog.dismiss();
}
});
}
});
}
}
Did you checked view in your onClick function like below..
#Override
public void onClick(View v) {
int id = v.getId();
switch (id) {
case R.id.attach_photo_camera_ImageView:
//your click code
break;
}
or try below code instad of your code..
mWorkDetailAttachImageView.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
}
});

Categories

Resources