New to android and I can't seem to be able to send any text to myself on my emulator. I have allowed permission in the manifest file and imported the necessary classes but still can't seem to figure out what's wrong. Any help would be greatly appreciated.
public class Detail extends AppCompatActivity {
public Button button5;
Spinner spinner2;
ArrayAdapter<CharSequence> adapter;
EditText editText4;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_detail);
editText4 = (EditText) this.findViewById(R.id.editText4);
button5 = (Button) findViewById(R.id.button5);
button5.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
String contact = editText4.getText().toString();
String message = "Help is on the way.";
sendMessage(contact,message);
Intent b = new Intent(Detail.this, End.class);
startActivity(b);
}
});
spinner2 = (Spinner) findViewById(R.id.spinner2);
adapter = ArrayAdapter.createFromResource(this,R.array.selectissue,android.R.layout.simple_spinner_item);
adapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
spinner2.setAdapter(adapter);
spinner2.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
#Override
public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
Toast.makeText(getBaseContext(),parent.getItemAtPosition(position) + " selected" , Toast.LENGTH_LONG).show();
}
#Override
public void onNothingSelected(AdapterView<?> parent) {
}
});
}
private void sendMessage(String contact, String message)
{
SmsManager smsManager = SmsManager.getDefault();
try {
smsManager.sendTextMessage(contact, null , message , null , null);
Toast.makeText(getApplicationContext(), "SMS Sent.", Toast.LENGTH_LONG).show();
} catch (Exception e)
{
Toast.makeText(getApplicationContext(), "SMS failed to send.", Toast.LENGTH_LONG).show();
}
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_detail, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Manifest
<?xml version="1.0" encoding="utf-8"?>
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.SEND_SMS"/>
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Login"
android:label="#string/title_activity_login" >
</activity>
<activity
android:name=".Option"
android:label="#string/title_activity_option" >
</activity>
<activity
android:name=".Detail"
android:label="#string/title_activity_detail" >
</activity>
<activity
android:name=".End"
android:label="#string/title_activity_end" >
</activity>
<activity
android:name=".Feedback"
android:label="#string/title_activity_feedback" >
</activity>
<activity
android:name=".Student"
android:label="#string/title_activity_student" >
</activity>
<activity
android:name=".Incident"
android:label="#string/title_activity_incident" >
</activity>
<activity
android:name=".Help"
android:label="#string/title_activity_help" >
</activity>
<activity
android:name=".Wifi"
android:label="#string/title_activity_wifi" >
</activity>
<activity
android:name=".Basic"
android:label="#string/title_activity_basic" >
</activity>
<activity
android:name=".Home"
android:label="#string/title_activity_home" >
</activity>
<activity
android:name=".Guide"
android:label="#string/title_activity_guide" >
</activity>
<activity
android:name=".VPN"
android:label="#string/title_activity_vpn" >
</activity>
<activity
android:name=".VDI"
android:label="#string/title_activity_vdi" >
</activity>
<activity
android:name=".Location"
android:label="#string/title_activity_location" >
</activity>
<activity
android:name=".Phone"
android:label="#string/title_activity_phone" >
</activity>
<activity
android:name=".config"
android:label="#string/title_activity_config" >
</activity>
<activity
android:name=".Script"
android:label="#string/title_activity_script" >
</activity>
<meta-data
android:name="com.facebook.sdk.ApplicationId"
android:value="#string/facebook_app_id" />
<activity
android:name="com.facebook.FacebookActivity"
android:label="#string/app_name"
android:screenOrientation="portrait" />
<provider
android:name="com.facebook.FacebookContentProvider"
android:authorities="com.facebook.app.FacebookContentProvider"
android:exported="true" />
<activity
android:name=".Register"
android:label="#string/title_activity_register" >
</activity>
<activity
android:name=".Signup"
android:label="#string/title_activity_signup" >
</activity>
</application>
You can not send text messages via emulator if you want to test SMS feature then test it on real android device with activated sim card.
Related
I have an Android Application where I want to display a Splash Screen for 6 seconds but the Splash Screen doesn't show up on opening the app, instead the screen which was previously my start-page shows up.
Here is the splashscreen.java file:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.os.Handler;
public class splashscreen extends AppCompatActivity {
private static int SPLASH_TIME_OUT = 6000;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splashscreen);
new Handler().postDelayed(new Runnable() {
// Using handler with postDelayed called runnable run method
#Override
public void run() {
Intent i = new Intent(splashscreen.this, LoginActivity.class);
startActivity(i);
// close this activity
//finish();
}
}, 6*1000);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_splashscreen, menu);
return true;
}
#Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
Here is my manifest file-
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.admin.doccorduser" >
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<!-- Splash screen -->
<activity
android:name=".splashscreen"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".LoginActivity"
android:label="#string/app_name" >
</activity>
<activity
android:name=".RegActivity"
android:label="#string/title_activity_reg" >
</activity>
<activity
android:name=".Services"
android:label="#string/title_activity_services" >
</activity>
<activity
android:name=".viewExistingApp"
android:label="#string/title_activity_view_existing_app" >
</activity>
<activity
android:name=".DocumentAdvisor"
android:label="#string/title_activity_document_advisor" >
</activity>
<activity
android:name=".ChangePassword"
android:label="#string/title_activity_change_password" >
</activity>
<activity
android:name=".TrackStatus"
android:label="#string/title_activity_track_status" >
</activity>
<activity
android:name=".ChildRegister"
android:label="#string/title_activity_child_register" >
</activity>
<activity
android:name=".FathersDetails"
android:label="#string/title_activity_fathers_details" >
</activity>
<activity
android:name=".MothersDetails"
android:label="#string/title_activity_mothers_details" >
</activity>
<activity
android:name=".AppNumber"
android:label="#string/title_activity_app_number" >
</activity>
<activity
android:name=".SignUp"
android:label="#string/title_activity_sign_up" >
</activity>
</application>
</manifest>
Here is the splashscreen.xml file-
<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:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="16dp"
android:paddingTop="56dp"
android:paddingBottom="56dp"
android:background="#drawable/back1"
tools:context="com.example.lenovo.doccorduser.splashscreen">
<ImageView
android:id="#+id/imgLogo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/foetus"
android:layout_alignTop="#+id/textView4"
android:layout_centerHorizontal="true" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageView"
android:src="#mipmap/doccord"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="DocCord"
android:textStyle="bold"
android:id="#+id/textView4"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:focusable="false"
android:textColor="#android:color/holo_orange_light" />
</RelativeLayout>
Please help...
First Clean Your project,
Build -> Clean Project
and Run Again. It will work.
Hi and Try this code :
SplashScreen.java
public class splashscreen extends AppCompatActivity {
#Override
protected void onCreate( Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.splashscreen);
Thread timerThread = new Thread(){
public void run(){
try{
sleep(6000);
}catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent intent = new Intent(splashscreen.this,MainActivity.class);
startActivity(intent);
}
}
};
timerThread.start();
}
#Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
}
SplashScreen.xml
,
<ImageView
android:src="#drawable/mobilewallpapers"
android:layout_width="match_parent"
android:layout_height="match_parent" />
AndroidManifest
<application
android:allowBackup="true"
android:icon="#mipmap/ic_launcher"
android:label="#string/app_name"
android:supportsRtl="true"
android:theme="#style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
</intent-filter>
</activity>
<activity android:name=".splashscreen">
<intent-filter>
<action android:name="android.intent.action.MAIN">
</action>
<category android:name="android.intent.category.LAUNCHER">
</category>
</intent-filter>
</activity>
</application>
hope it works ;)
I am using some checkboxes and it is displayed on a dialogbox(dynamically).The next thing i need to make that dialog box transparent.I tried many methods,but failed(wasted the entire day behind this).Can anyone please give me a solution
NB:Currently i am getting a white colour inside the dialog box(Not transparent)
Below is the code.....
Transparent_alert.java
public class Transparent_alert extends Activity{
String tag="Transparent_alert class";
static final String KEY_USERID = "userid";
String errormsg = "", user_id;
SessionManager session;
int k=0;
Intrested_in_adapter m_adapter;
private Builder mDialog;
private Dialog alertDialog;
List<Requestencapsulation> offferList;
List<Offeringencapsulation> offerlist;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
HashMap<String, String> user = session.getUserDetails();
user_id = user.get(SessionManager.KEY_ID);
setContentView(R.layout.requests);
new Serviceclass1().execute();
}
class Serviceclass1 extends
AsyncTask<Void, Void, String> {
#Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
UserFunctions usf = new UserFunctions();
Log.e(tag,"user_id"+user_id);
JSONObject json2 = usf.intrestlist(user_id);
JSONArray contacts = json2
.getJSONArray("interested_list");
for (int j = 0; j < contacts.length(); j++) {
Log.e(tag, "intrestedin forloop");
JSONObject c = contacts
.getJSONObject(j);
Requestencapsulation bean = new Requestencapsulation();
bean.setIntrest_id(c
.getString("interested_id"));
bean.setIntrest_name(c
.getString("interested_name"));
bean.setKey_status(c
.getString("status"));
if (c.getString("interested_info")
.equals("null"))
{
bean.setInterested_info("");
} else {
bean.setInterested_info(c
.getString("interested_info"));
}
offferList.add(bean);
}
k=offferList.size();
}
catch (Exception e) {
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
new Serviceclass2().execute();
}
}
class Serviceclass2 extends
AsyncTask<Void, Void, String> {
#Override
protected String doInBackground(Void... params) {
// TODO Auto-generated method stub
try {
UserFunctions usf1 = new UserFunctions();
JSONObject json3= usf1.offerlistlist(user_id);
JSONArray contacts1 = json3.getJSONArray("offer_list");
for (int i = 0; i < contacts1.length(); i++) {
Log.e(tag,"INSIDE OFFERING LOOP");
JSONObject d= contacts1.getJSONObject(i);
Log.e(tag,"CREATED JSON OBJECT");
Requestencapsulation bean=new Requestencapsulation();
Log.e(tag,"OBJECT CREATED FOR OFFERINGENCAPSULATION");
bean.setIntrest_id(d
.getString("offer_id"));
Log.e(tag,
"offerid is::"
+ d.getString("offer_id"));
bean.setIntrest_name(d
.getString("offer_name"));
Log.e(tag,
"offer name is::"
+ d.getString("offer_name"));
bean.setKey_status(d.getString("status"));
Log.e(tag,
"status is"
+ d.getString("status"));
// if (d.getString("offer_info").equals(
// "null")) {
// bean.setInterested_info(d
// .getString("interested_info"));
// } else {
// bean.setInterested_info(d
// .getString("interested_info"));
//
// }
offferList.add(bean);
Log.e(tag,"process for bean1 completed");
;
}
} catch (JSONException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
protected void onPostExecute(String result) {
new Serviceclass2().execute();
Context c = getParent();
m_adapter = new Intrested_in_adapter(
Transparent_alert.this,
R.layout.intrestedin, offferList);
mDialog = new AlertDialog.Builder(c);
mDialog.setTitle("Intrested In");
mDialog.setAdapter(m_adapter,
new DialogInterface.OnClickListener() {
public void onClick(
DialogInterface dialog,
int item) {
}
});
alertDialog = mDialog.create();
alertDialog.show();
}
}
intrestedin.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"
>
<CheckBox
android:id="#+id/checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="#000000"
/>
</LinearLayout>
Intrested_in_adapter.java
public class Intrested_in_adapter extends ArrayAdapter<Requestencapsulation>{
CheckBox checkbox;
CheckBox checkbox1;
private List<Requestencapsulation> alist;
private List<Offeringencapsulation> alist1;
public Intrested_in_adapter(Context context, int textViewResourceId) {
super(context, textViewResourceId);
}
public Intrested_in_adapter(Context context, int resource, List<Requestencapsulation> items) {
super(context, resource,items);
this.alist=items;
Log.e("Inside Constructor","list size is:"+alist.size());
}
#Override
public Requestencapsulation getItem(int position) {
return alist.get(position);
}
public long getId(int position)
{
return position;
}
#Override
public View getView(int position, View convertView, ViewGroup parent) {
// ViewHolder mHolder;
Requestencapsulation p = getItem(position);
if (convertView == null) {
Log.e("inside convertview","inside convertview");
convertView = LayoutInflater.from(getContext()).inflate(R.layout.intrestedin, parent, false);
}
if (p != null) {
// mHolder = new ViewHolder();
checkbox=(CheckBox)convertView.findViewById(R.id.checkbox);
if(alist.get(position).getKey_status().equalsIgnoreCase("true"))
{
checkbox.setSelected(true);
}else{
checkbox.setSelected(false);
}
checkbox.setText(alist.get(position).getIntrest_name());
}
return convertView;
}
}
maifest.xml
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.gatekeeper.dropswitch"
android:installLocation="auto"
android:largeHeap="true"
android:versionCode="3"
android:versionName="1.1" >
<uses-sdk
android:minSdkVersion="9"
android:targetSdkVersion="18" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
android:name="com.example.gate.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="com.example.gate.permission.C2D_MESSAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<application
android:allowBackup="true"
android:icon="#drawable/gate_logo"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name="com.example.gate.Redirectclass"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:theme="#android:style/Theme.NoTitleBar"
android:name="com.example.gate.Userpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Transparent_alert"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.Translucent.NoTitleBar.Fullscreen" >
</activity>
<activity
android:name="com.example.gate.Registerpage"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.ProfileActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Selectbuttonfromrequestclass"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.gate.Actionclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.TabGroup1Activity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Tabgroup2"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Tabgroup3"
android:screenOrientation="portrait" >
</activity>
<activity android:name="com.example.gate.MainActivity"
android:screenOrientation="portrait">
</activity>
<activity
android:name="com.example.gate.Home"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Homenext"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Family"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.FamilyMain"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Familyedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.GuestMain"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guest"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guestedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Services"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Addprovider"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Addservices"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Offering"
android:screenOrientation="portrait"
android:windowSoftInputMode="adjustPan" >
</activity>
<activity
android:name="com.example.gate.Interest"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Accesspreferences"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.ActionActivity"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Messageclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Report"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Requestclass"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Notify"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Rsidenceinfo"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Latestservice"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardactiongroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardprofilegroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardinfogroup"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Otherresidence"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Directoryguardedit"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardaction"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.skype.raider.Main"
android:configChanges="keyboardHidden|orientation"
android:launchMode="singleTask"
android:windowSoftInputMode="adjustResize" >
<intent-filter android:priority="0" >
<action android:name="android.intent.action.CALL_PRIVILEGED" />
<category android:name="android.intent.category.DEFAULT" />
<data android:scheme="tel" />
</intent-filter>
</activity>
<activity
android:name="com.example.gate.Guardinfo"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guardprofile"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.video"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_message_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_report_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_notify_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.Guard_request_class"
android:screenOrientation="portrait" >
</activity>
<activity
android:name="com.example.gate.guard_addnew_residence"
android:screenOrientation="portrait" >
</activity>
<receiver
android:name="com.example.gate.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<!-- Receives the actual messages. -->
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="com.example.gate" />
</intent-filter>
</receiver>
<service android:name="com.example.gate.GcmIntentService" />
<meta-data
android:name="com.google.android.gms.version"
android:value="#integer/google_play_services_version" />
</application>
</manifest>
I am not getting any clue to do this .Please anybody help.Any help will be highly appreciated....
try making your dialog transparent, like this
intrestedin.xml
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:background="#android:color/transparent"
if you wanna make your alertdialog transparent i don't know if it's possible but customizing an alertdialog like the code as displayed below is more suitable for this you just need to create an xml file which makes a design exactly similar to your current alert box and can make it as transparent.
dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.dialog_profile_report);
dialog.setCanceledOnTouchOutside(false);
dialog.getWindow().setBackgroundDrawable(
new ColorDrawable(android.graphics.Color.TRANSPARENT));
dialog.show();
Button mainListView = (Button) dialog.findViewById(R.id.listview); // you can declare elements like this and can make onclick methods for these elements
Replace
alertDialog = mDialog.create();
alertDialog.show();
with
alertDialog = mDialog.create();
alertDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
alertDialog.show();
Issue:
Your adapter is inflating row layout to display in ListView. and as you can see, it is going to reference with Parent container while inflating using LayoutInflater.
It is creating problem while making everything transparent.
Option 1 :
You should consider using Dialog instead of AlertDialog and should set your desired layout by using setContentView
Option 2 :
You will have some drawback because of old api but it will work in new apis
replace
mDialog = new AlertDialog.Builder(c);
with
mDialog = (Integer.parseInt(android.os.Build.VERSION.SDK) < 11)? new AlertDialog.Builder(c) :new AlertDialog.Builder(c, android.R.style.Theme_Translucent);
please put below code in style
<style name="CustomAlert" parent="android:Theme.Dialog">
<item name="android:windowBackground">#android:color/transparent</item>
<item name="android:windowIsFloating">true</item>
<item name="android:windowContentOverlay">#null</item>
<item name="android:windowAnimationStyle">#android:style/Animation.Dialog</item>
<item name="android:windowSoftInputMode">stateUnspecified|adjustPan</item>
<item name="android:backgroundDimEnabled">false</item>
<item name="android:background">#android:color/transparent</item>
</style>
Code:
Dialog mDialog = new Dialog(baseApplication.getCurrentActivity(),
R.style.CustomAlert);
mDialog.setCancelable(true);
mDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
mDialog.setContentView(R.layout.inflate_toast);
//you can set height width of dialog as well as position
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
Window window = mDialog.getWindow();
lp.copyFrom(window.getAttributes());
lp.width = WindowManager.LayoutParams.MATCH_PARENT;
lp.height = WindowManager.LayoutParams.WRAP_CONTENT;
lp.gravity = Gravity.TOP;
window.setAttributes(lp);
mDialog.show();
In your activity xml:
set background as transparent color to listview, listview's divider,and inflated layout of listview.
I'm creating a menu where all of my activity will be on the list, and whenever i clicked an activity from that list, it should start that activity.
here is my menu.java
public class Menu extends ListActivity
{
String classnames[] = {"MainActivity","example1","example2","example3",
"example4","example5","example6","example7","example8","example9","example10"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classnames));
}
protected void onListItemClick(ListView l, View v, int position, long id)
{
super.onListItemClick(l, v, position, id);
String classClicked = classnames[position];
try
{
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(Menu.this,ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
}
here is my manifest:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
</application>
It don't have any error but my MainActivity doesn't start even when I clicked it.
Here's what it looks like:
Use getListView().setOnItemClickListener instead of onListItemClick. Why? to be honest i also dont know, but it solved my problem.
You must declare all your activities in AndroidManifest.xml otherwise it won't work. Your updated manifest file should look like this:
<application
android:allowBackup="true"
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Menu"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".MainActivity"
android:label="#string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAINACTIVITY" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<activity
android:name=".example1"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example2"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example3"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example4"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example5"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example6"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example7"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example8"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example9"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
<activity
android:name=".example10"
android:label="#string/app_name"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
</application>
Menu.java
public class Menu extends ListActivity
{
String classnames[] = {"MainActivity","example1","example2","example3",
"example4","example5","example6","example7","example8","example9","example10"};
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setListAdapter(new ArrayAdapter<String>(Menu.this,android.R.layout.simple_list_item_1,classnames));
getListView().setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, final int position, long l) {
String classClicked = classnames[position];
try {
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(getApplicationContext(),ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}
}
});
}
protected void onListItemClick(ListView l, View v, int position, long id)
{
/*super.onListItemClick(l, v, position, id);
String classClicked = classnames[position];
try
{
Class ourclass = Class.forName("android.intent.action."+classClicked);
Intent intent = new Intent(Menu.this,ourclass);
startActivity(intent);
}
catch(ClassNotFoundException e)
{
e.printStackTrace();
}*/
}
}
And now everything should work.
You must register the other activities in your manifest, just like the mainactivity. Otherwise Android wont start them.
I am creating a Jigsaw Puzzle application in android. I have created two activites, activity_jigsaw.xml and activity_level.xml. One activity is created by default (Displaying Hello World!) which I modified and created a new activity by following these steps:
File -> New -> Other -> Android Activity
But when I install the application these two files (and all other activities of the application) are installed as a separate project. But at the same time they are also interlinked. The Java code of the files as follows:
Jisaw.java file contains:
public class Jigsaw extends Activity {
Intent intent;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_jigsaw);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_jigsaw, menu);
return true;
}
public void play(View v)
{
try
{
intent = new Intent(this, Level.class);
startActivity(intent);
}
catch(Exception e)
{
e.printStackTrace();
}
}
}
Here Play is a function which is called when an image is clicked.
Level.java file contains:
public class Level extends Activity {
Intent intent;
String level = "";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_level);
}
#Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.activity_level, menu);
return true;
}
public void easy(View v)
{
level = "easy";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void medium(View v)
{
level = "medium";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
public void hard(View v)
{
level = "hard";
intent = new Intent(this, Play.class);
intent.putExtra("level", level);
startActivity(intent);
}
}
Functions easy, medium and hard are called when a corresponding image is clicked.
Can somebody please tell me that what I am doing wrong?
Thanks in advance..
Here is the manifest file:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.maju.jigsawpuzzle"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="15" />
<uses-permission android:name="android.permission.SET_WALLPAPER" />
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name"
android:theme="#style/AppTheme" >
<activity
android:name=".Jigsaw"
android:label="#string/title_activity_jigsaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Level"
android:label="#string/title_activity_level" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Play"
android:label="#string/title_activity_play" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".PlayBoard"
android:label="#string/title_activity_play_board" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>
You probably are defining android.intent.category.LAUNCHER intent category to all the activities in your AndroidManifest.xml, it creates an icon in the app launcher. Activities other than main should not have this intent filter.
Do something like this:
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity android:name=".JigSaw" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".Level" />
<activity android:name=".Play" />
<activity android:name=".Playboard" />
</application>
EDIT:
As you just posted, you are indeed doing that, just remove the intent filter from other activities.
So i have this activity :
public class settings_dock extends Activity {
AlertDialog alert;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.settings);
//Weather settings
ListView listView = (ListView) findViewById(R.id.settings);
String[] values = new String[] { "Enable/Disable","Configure Item 1","Configure Item 2","Configure Item 3","Configure Item 4"};
ArrayAdapter<String> adapter = new ArrayAdapter<String>(this,
android.R.layout.simple_list_item_1, android.R.id.text1, values);
// Assign adapter to ListView
listView.setAdapter(adapter);
listView.setOnItemClickListener(new OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
if(position == 0)
{
final CharSequence[] items = {"Enabled", "Disabled"};
AlertDialog.Builder builder = new AlertDialog.Builder(settings_dock.this);
builder.setTitle("The Dock is ....");
SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);
builder.setSingleChoiceItems(items,dock.getInt("enabled_disabled",-1), new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
SharedPreferences dock = app.getContext().getSharedPreferences("dock",app.getContext().MODE_WORLD_READABLE);
SharedPreferences.Editor prefsEditor = dock.edit();
prefsEditor.putInt("enabled_disabled",item);
prefsEditor.commit();
alert.dismiss();
if(item == 0)
{
}
if(item == 1)
{
}
}
});
alert = builder.create();
alert.show();
}
if(position == 1)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",1);
}
if(position == 2)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",2);
}
if(position == 3)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",3);
}
if(position == 4)
{
Intent in=new Intent(settings_dock.this,set_dock.class);
in.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
in.putExtra("dock_location",4);
}
}
});
}
}
and I am trying to launch a intent as you can see
but simplay nothing happens not even a error in logcat
The intent to launch is lusted in my manifest
I am realy puzzeld right now :(
m
edit :
manifest :
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="org.alexander.fuchs.lockscreen"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk android:minSdkVersion="8" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"/>
<uses-permission android:name="android.permission.DISABLE_KEYGUARD"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.INTERNET"/>
<application
android:icon="#drawable/ic_launcher"
android:label="#string/app_name" >
<activity
android:name=".app"
android:label="#string/app_name"
android:screenOrientation="portrait"
android:theme="#android:style/Theme.NoTitleBar.Fullscreen"
android:excludeFromRecents="true"
android:clearTaskOnLaunch="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver android:name="boot">
<intent-filter>
<action android:name="android.intent.action.BOOT_COMPLETED"/>
<category android:name="android.intent.category.HOME" />
</intent-filter>
</receiver>
<service
android:name="lockservice"
android:process=":lockscreen"
android:icon="#drawable/ic_launcher"
android:label="Lockscreen">
</service>
<activity
android:name=".weather_update"
android:theme="#android:style/Theme.Translucent">
</activity>
<activity
android:name=".restart_service"
android:theme="#android:style/Theme.Translucent">
</activity>
<activity
android:name=".settings">
</activity>
<activity
android:name=".settings_weather">
</activity>
<activity
android:name=".settings_general">
</activity>
<activity
android:name=".settings_dock">
</activity>
<activity
android:name=".settings_personalisation">
</activity>
<activity
android:name=".set_dock"
android:theme="#android:style/Theme.Dialog"
android:screenOrientation="portrait">
</activity>
</application>
</manifest>
You haven't called:
startActivity(in);
Hopefully this helps.
Try adding startActivity(in) in each of the if statement. To start an activity you need to call startActivity(intent) method.