Android Activity as dialog black border - android

I have activity as a dialogue, all the shows I like. But I have a problem with a frame around them. Just like here.
My Activity:
public class AlarmAlert extends Activity implements Alarms.AlarmSettings {
#Override
protected void onCreate(Bundle icicle) {
super.onCreate(icicle);
AlarmAlertWakeLock.acquire(this);
/*
* FIXME Intentionally verbose: always log this until we've fully
* debugged the app failing to start up
*/
Log.v("AlarmAlert.onCreate()");
DigitalClock dc = (DigitalClock) findViewById(R.id.digitalClock1);
mKeyguardManager = (KeyguardManager) getSystemService(Context.KEYGUARD_SERVICE);
Intent i = getIntent();
mAlarmId = i.getIntExtra(Alarms.ID, -1);
Alarms.getAlarm(getContentResolver(), this, mAlarmId);
mKlaxon = new AlarmKlaxon();
mKlaxon.postPlay(this, mAlarmId);
/* Set the title from the passed in label */
setTitleFromIntent(i);
/*
* allow next alarm to trigger while this activity is active
*/
Alarms.disableSnoozeAlert(AlarmAlert.this);
Alarms.disableAlert(AlarmAlert.this, mAlarmId);
Alarms.setNextAlert(this);
mKlaxon.setKillerCallback(new AlarmKlaxon.KillerCallback() {
public void onKilled() {
if (Log.LOGV)
Log.v("onKilled()");
updateSilencedText();
/* don't allow snooze */
mSnoozeButton.setEnabled(false);
dismiss();
mState = KILLED;
}
});
updateLayout();
SharedPreferences settings = getSharedPreferences(
AlarmClock.PREFERENCES, 0);
if (settings.getBoolean(AlarmClock.PREF_SHAKE_SNOOZE, true)) {
mShakeListener = new ShakeListener(this);
mShakeListener
.setOnShakeListener(new ShakeListener.OnShakeListener() {
public void onShake() {
snooze();
if (mCaptchaSnooze == 0)
finish();
}
});
}
}
private void setTitleFromIntent(Intent i) {
mLabel = i.getStringExtra(Alarms.LABEL);
if (mLabel == null || mLabel.length() == 0) {
mLabel = getString(R.string.default_label);
}
setTitle(mLabel);
}
private void updateSilencedText() {
TextView silenced = (TextView) findViewById(R.id.silencedText);
silenced.setText(getString(R.string.alarm_alert_alert_silenced,
mDuration / 1000 * 60));
silenced.setVisibility(View.VISIBLE);
}
private void updateLayout() {
setContentView(R.layout.alarm_alert);
My alert_alarm.xml (Dialog).
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/root"
android:layout_width="327dp"
android:layout_height="295dp"
android:background="#drawable/alertbg"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:id="#+id/silencedText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:paddingBottom="2dp"
android:paddingTop="2dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#color/ltgrey"
android:visibility="gone" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="230dp"
android:gravity="center_horizontal" >
<Button
android:id="#+id/snooze"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/snooze_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
<Button
android:id="#+id/dismiss"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="25dp"
android:layout_marginTop="20dp"
android:background="#drawable/teesstt"
android:text="#string/dismiss_button"
android:textColor="#fff"
android:textSize="25dp"
android:visibility="visible" />
</RelativeLayout>
<TextView
android:id="#+id/tvDD"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/tvDate"
android:layout_alignLeft="#+id/tvDate"
android:text="Medium Text"
android:textSize="20dp"
android:textColor="#a6a6a6" />
<TextView
android:id="#+id/tvDate"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/relativeLayout1"
android:layout_alignParentLeft="true"
android:layout_marginBottom="55dp"
android:layout_marginLeft="30dp"
android:text="Medium Text"
android:textSize="25dp"
android:textColor="#a6a6a6" />
<com.boxclocks.android.alarmclock.dc
android:id="#+id/digitalClock1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="30dp"
android:layout_marginTop="58dp"
android:text="DigitalClock"
android:textColor="#a6a6a6"
android:textSize="70dp" />
</RelativeLayout>
How do I remove the border.

dialog.getWindow().setBackgroundDrawableResource(android.R.color.transparent);
Dialog

You have two options. You can set the theme of your Activity to
Theme_Translucent_NoTitleBar
Or you have to create a new theme and load it with a custom nine patch as specified here
How to remove border from Dialog?

Related

relaunch application without changing

I found some code to press home button from code
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
and This one :
moveTaskToBack(true);
I have a activity that is in single task
And a alertDialog with a button then you click on the button one of those code run and go to home
so when you go to app again the alert dismissed before
I want to relaunch the app without dismissing alertDialog
What can i do?
thanks
AlertDialog default button will dissmis dialog .
you should create custom dialog with custom view
public class CustomDialog extends AlertDialog(){
TextView mTitleView,mDescriptionView;
Button mYesButton,mNoButton,mCancelButton;
boolean isYesButtonVisible = true;
boolean isNoButtonVisible = true;
boolean isCancelButtonVisible = true;
public CustomDialog(Context context){
super(context);
}
public void setYesButtonVisible(boolean isVisible){
isYesButtonVisible = isVisible
}
public void setNoButtonVisible(boolean isVisible){
isNoButtonVisible = isVisible
}
public void setCancelButtonVisible(boolean isVisible){
isCancelButtonVisible = isVisible
}
#override
public void show(){
super.show();
setContentView(R.layout.dialog_custom);
mTitleView = findViewById(R.id.text_title);
mDescriptionView = findViewById(R.id.text_description);
mYesButton = findViewById(R.id.btn_yes);
mNoButton = findViewById(R.id.btn_no);
mCancelButton = findViewById(R.id.btn_cancel);
isYesButtonVisible ? mYesButton.setVisibility(View.VISIBLE) : mYesButton.setVisibility(View.GONE);
isNoButtonVisible ? mNoButton.setVisibility(View.VISIBLE) : mNoButton.setVisibility(View.GONE);
isCancelButtonVisible ? mCancelButton.setVisibility(View.VISIBLE) : mCancleButton.setVisibility(View.GONE);
}
//must be called after dialog is showing else you will get NullPointerException
public void setOnYesClickListener(View.OnClickListener listener){
mYesButton.setonClickListener(listener);
}
public void setOnNoClickListener(View.OnClickListener listener){
mNoButton.setonClickListener(listener);
}
public void setOnCancelClickListener(View.OnClickListener listener){
mCancelButton.setonClickListener(listener);
}
}
and layout dialog_custom can be designed by yourself too but this is my layout file for custom dialog
<?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">
<TextView
android:id="#+id/text_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/text_description"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="#+id/btn_yes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/yes"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/btn_no"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/no"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#id/btn_cancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:paddingBottom="8dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp"
android:text="#string/cancel"
android:textColor="#color/green_click"
android:textSize="18sp"
android:textStyle="bold" />
</LinearLayout>
While creating AlertDialog with Builder you can set setCancelable(false);.

Error:NullPointerException when put button.setOnclickListener in onResponse method [duplicate]

This question already has answers here:
What is a NullPointerException, and how do I fix it?
(12 answers)
Closed 6 years ago.
When i click my button in my activity, it will stop and show an error like this :
Caused by: java.lang.NullPointerException: Attempt to invoke virtual method 'void android.widget.Button.setOnClickListener(android.view.View$OnClickListener)' on a null object reference
In my activity, i put button.setOnclickListener in onResponse() method from Response.Listener. I do this because i want to get the data from JSONObject and use that data when i click my button.
Sorry, I'm not too fluent in English :)
My activity code:
public class MenuDaftarNilai2 extends AppCompatActivity {
TextView tvMatkulDN, tvKlpDN, tvMhsDN;
Button bUasDN;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_menu_daftar_nilai2);
tvMatkulDN = (TextView) findViewById(R.id.tvMatkulDN) ;
tvKlpDN = (TextView) findViewById(R.id.tvKlpDN) ;
tvMhsDN = (TextView) findViewById(R.id.tvMhsDN) ;
bUasDN = (Button) findViewById(R.id.bUasDN) ;
Intent intent = getIntent();
final String nama_matkul = intent.getStringExtra("nama_matkul");
final String nama_klp = intent.getStringExtra("nama_klp");
final String nama_mhs = intent.getStringExtra("nama_mhs");
tvMatkulDN.setText(nama_matkul);
tvKlpDN.setText(nama_klp);
tvMhsDN.setText(nama_mhs);
Response.Listener responseListener1 = new Response.Listener<String>() {
#Override
public void onResponse(String response) {
try {
JSONObject jsonResponse = new JSONObject(response);
final String nilai_uas = jsonResponse.getString("nilai_uas");
final String id_uas = jsonResponse.getString("id_uas");
bUasDN.setText("Nilai Uas : " + nilai_uas);
bUasDN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MenuDaftarNilai2.this, EditUas.class);
intent.putExtra("nilai_uas", nilai_uas);
intent.putExtra("nama_matkul", nama_matkul);
intent.putExtra("nama_klp", nama_klp);
intent.putExtra("nama_mhs", nama_mhs);
intent.putExtra("id_uas", id_uas);
MenuDaftarNilai2.this.startActivity(intent);
finish();
}
});
}catch (JSONException e) {
e.printStackTrace();
}
}
};
ResponUas resUas = new ResponUas(nama_klp,nama_mhs, responseListener1);
RequestQueue queue1 = Volley.newRequestQueue(MenuDaftarNilai2.this);
queue1.add(resUas);
My XML code:
<?xml version="1.0" encoding="utf-8"?>
<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=".LoginAsis.MenuAsisten.MenuDaftarNilai.MenuDaftarNilai2"
android:background="#ad4f4f">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Mata Kuliah"
android:id="#+id/textView54"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Kelompok"
android:id="#+id/textView58"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView54"
android:layout_alignParentLeft="true"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Nama Mahasiswa"
android:id="#+id/textView59"
android:layout_alignParentStart="true"
android:layout_below="#+id/textView58"
android:layout_alignParentLeft="true"
android:textColor="#ffffff" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:id="#+id/textView60"
android:textColor="#ffffff"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/textView61"
android:layout_alignStart="#+id/textView61" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:id="#+id/textView61"
android:textColor="#ffffff"
android:layout_below="#+id/textView60"
android:layout_alignLeft="#+id/textView62"
android:layout_alignStart="#+id/textView62" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=":"
android:id="#+id/textView62"
android:textColor="#ffffff"
android:layout_marginLeft="68dp"
android:layout_marginStart="40dp"
android:layout_below="#+id/textView61"
android:layout_toRightOf="#+id/textView54"
android:layout_toEndOf="#+id/textView54" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvMatkulDN"
android:layout_alignTop="#+id/textView60"
android:layout_toRightOf="#+id/textView60"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvKlpDN"
android:layout_below="#+id/tvMatkulDN"
android:layout_toRightOf="#+id/textView60"
android:textColor="#ffffff"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Medium Text"
android:id="#+id/tvMhsDN"
android:layout_below="#+id/tvKlpDN"
android:layout_toRightOf="#+id/textView61"
android:textColor="#ffffff"
android:layout_alignRight="#+id/tvKlpDN"
android:layout_alignEnd="#+id/tvKlpDN"
/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Belum ada nilai uas"
android:id="#+id/bUasDN"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_below="#id/textView59"
android:gravity="left|center_vertical"
android:drawableRight="#drawable/ic_create_black_24dp"/>
</RelativeLayout>
just put this outside the response parenthesis ...............
bUasDN.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(MenuDaftarNilai2.this, EditUas.class);
intent.putExtra("nilai_uas", nilai_uas);
intent.putExtra("nama_matkul", nama_matkul);
intent.putExtra("nama_klp", nama_klp);
intent.putExtra("nama_mhs", nama_mhs);
intent.putExtra("id_uas", id_uas);
MenuDaftarNilai2.this.startActivity(intent);
finish();
}
});
enjoy coding..........

How to avoid startActivty(new Intent()) method starting more than one Activities?

I just do my project but when I test my app I found that then I touch the screen by using more than one fingers my app may start two or three different activities.
The activities all go to the back stack. Is this a bug in Android framework? But I can't reappear this condition, it just happened.
So, have you guys ever have this problem? Please come and discuss with me. If you do; Thanks.
Supply:
And here is My xml file , when I click the different RelativeLayout at the same time , it happened.
I tried this afternoon , but this condition is not appear anymore. Now I am confusing.
<LinearLayout android:layout_width="match_parent"
android:orientation="vertical"
android:background="#color/appDefaultSingleBlockBackground"
android:layout_height="wrap_content">
<RelativeLayout android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:background="#drawable/mine_bg"
android:id="#+id/mine_goto_personal_info_btn"
>
<TextView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:id="#+id/mine_nick_and_avatar"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextTitle"
android:textColor="#color/appDefaultSingleBlockBackground"
android:text=""/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_interesting_venue"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_attentionbutton"
android:text="#string/myAtentionVenue"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_setting"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_setbutton"
android:text="#string/setting"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_youhuijuan"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_discountbutton"
android:text="#string/youhuijuan"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_my_rest_money"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_balancebutton"
android:text="#string/myRest"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="#color/dividerdefault"
/>
<RelativeLayout android:layout_width="match_parent"
android:layout_height="50dp"
android:background="#color/appDefaultSingleBlockBackground"
android:clickable="true"
android:id="#+id/mine_goto_secure"
>
<TextView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:gravity="center_vertical"
android:drawablePadding="10dp"
android:layout_marginLeft="15dp"
style="#style/TextNomal"
android:drawableLeft="#drawable/information_accountssafebutton"
android:text="#string/secure"/>
<ImageView android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="#drawable/venue_maxbutton"
android:layout_centerVertical="true"
android:layout_alignParentRight="true"
android:layout_marginRight="15dp"
/>
</RelativeLayout>
<View android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#color/dividerdefault"
/>
</LinearLayout>
and this is my java code .
private void init(View ret) {
final TextView txtAvatar = (TextView) ret.findViewById(R.id.mine_nick_and_avatar);
final RelativeLayout gotoPersonal = (RelativeLayout) ret.findViewById(R.id.mine_goto_personal_info_btn);
RelativeLayout gotoInterest = (RelativeLayout) ret.findViewById(R.id.mine_goto_interesting_venue);
RelativeLayout gotoSetting = (RelativeLayout) ret.findViewById(R.id.mine_goto_setting);
RelativeLayout gotoYouhuijuan = (RelativeLayout) ret.findViewById(R.id.mine_goto_youhuijuan);
RelativeLayout gotoMyRestMoney = (RelativeLayout) ret.findViewById(R.id.mine_goto_my_rest_money);
RelativeLayout gotoSecure = (RelativeLayout) ret.findViewById(R.id.mine_goto_secure);
gotoPersonal.setTag("gotoPersonal");
gotoInterest.setTag("gotoInterest");
gotoSetting.setTag("gotoSetting");
gotoYouhuijuan.setTag("gotoYouhuijuan");
gotoMyRestMoney.setTag("gotoMyRestMoney");
gotoSecure.setTag("gotoSecure");
try {
Object o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[1]);
if (o != null && !"null".equals(o)) {
txtAvatar.setText((String) o);
} else {
o = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[10]);
if (o != null && !"null".equals(o))
txtAvatar.setText("KD" + o);
}
} catch (Exception e) {
}
Object o1 = SharedPreferenceUtils.readInfo(mActivity, ConstData.UserInfo[2]);
if (o1 != null)
MyApplication.downloader.download("http://" + o1, new ImageDownloadStateListener() {
#Override
public void loading() {
}
#Override
public void loadSuccess(Bitmap bitmap, String url) {
try {
bitmap = Tools.transforCircleBitmap(bitmap);
BitmapDrawable drawable = new BitmapDrawable(getResources(), bitmap);
gotoPersonal.measure(0, 0);
int measuredHeight = gotoPersonal.getMeasuredHeight();
LogHelper.print("==height" + measuredHeight);
drawable.setBounds(0, 0, measuredHeight / 5 * 4, measuredHeight / 5 * 4);
txtAvatar.setCompoundDrawables(drawable, null, null, null);
} catch (Exception e) {
//no nothing
}
}
#Override
public void loadFailed() {
}
});
gotoPersonal.setOnClickListener(this);
gotoInterest.setOnClickListener(this);
gotoSetting.setOnClickListener(this);
gotoYouhuijuan.setOnClickListener(this);
gotoMyRestMoney.setOnClickListener(this);
gotoSecure.setOnClickListener(this);
}
#Override
public void onResume() {
initActionBar();
super.onResume();
MobclickAgent.onPageStart(getClassName()); //统计页面
}
#Override
public void onPause() {
super.onPause();
MobclickAgent.onPageEnd(getClassName());
}
private String getClassName() {
String canonicalName = this.getClass().getCanonicalName();
String[] split = canonicalName.split("\\.");
return split[split.length - 1];
}
private void initActionBar() {
MyActivity activity = (MyActivity) mActivity;
activity.setActionBarLeftImg(new ColorDrawable(Color.TRANSPARENT), false);
activity.setActionBarRightImg(new ColorDrawable(Color.TRANSPARENT));
activity.setOnActionBarLeftClickListener(null);
activity.setOnActionBarRightClickListener(null);
activity.setActionBarTitle("个人中心");
}
#Override
public void onClick(View v) {
Object tag = v.getTag();
if (tag != null) {
String str = (String) tag;
if (mActivity == null) {
return;
}
if (!((MyActivity) (mActivity)).isLogin) {
Intent intent = new Intent(mActivity, LoginActivity.class);
startActivity(intent);
return;
}
if (!TextUtils.isEmpty(str))
if ("gotoPersonal".equals(str)) {
Intent intent = new Intent(mActivity, PersonalInfoActivity.class);
startActivity(intent);
} else if ("gotoInterest".equals(str)) {
Intent intent = new Intent(mActivity, VenueListActivity.class);
intent.putExtra("isInterests", true);
startActivity(intent);
} else if ("gotoSetting".equals(str)) {
Intent intent = new Intent(mActivity, SettingActivity.class);
startActivity(intent);
} else if ("gotoYouhuijuan".equals(str)) {
Intent intent = new Intent(mActivity, FavorableActivity.class);
startActivity(intent);
} else if ("gotoSecure".equals(str)) {
Intent intent = new Intent(mActivity, SecureActivity.class);
startActivity(intent);
} else if ("gotoMyRestMoney".equals(str)) {
Intent intent = new Intent(mActivity, MyRestActivity.class);
startActivity(intent);
}
}
}
You need to define the launch mode. There are at least two ways of solving this by either using the manifest file (hint: singleTop) or by using Intent flags (hint: FLAG_ACTIVITY_SINGLE_TOP).
Good luck!
Simpliest approach would be disable control that starts your Activity (button for example) after 1 click, and enable it later with some condition or action. Try it.
You can use this approach.......
((Button)findViewById(R.id.someButton)).setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
((Button)findViewById(R.id.someButton)).setEnabled(false);
}
});
Happy coding

getCheckedRadioButtonId just gives me nullpoint exception

Im having some issues, i have two Groups of Radiobuttons in my XML which has handling in an activity. It just crashes with nullpoint exception on line 48:
int languangeId = languageGroup.getCheckedRadioButtonId();
I have set a "default" checked button in the XML to one of the buttons in the buttongroup,
So why doesnt it get an valid value?:(
public class FirstTimeSelectMenu extends Activity{
private RadioGroup languageGroup;
private RadioGroup storageGroup;
private Button okButton;
private String getStorage;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.first_time_run);
languageGroup = (RadioGroup)this.findViewById(R.id.languageGroup);
storageGroup = (RadioGroup)this.findViewById(R.id.storageGroup);
okButton = (Button)findViewById(R.id.okBtn);
okButton.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
int languangeId = languageGroup.getCheckedRadioButtonId();
int storageId = storageGroup.getCheckedRadioButtonId();
RadioButton languageb = (RadioButton)findViewById(languangeId);
RadioButton storageb = (RadioButton)findViewById(storageId);
if(languageb.equals("Norwegian")){
//Need to fix this!
}
if(languageb.equals("English")){
//Need to fix this!
}
if(storageb.equals("SD Card")){
String sdStoragePath = Environment.getExternalStorageDirectory().toString() + "/PictureTalk/";
FileInteraction fi = new FileInteraction();
fi.firstTimeFillPath(getResources(), "PictureTalk/Food", sdStoragePath +"PictureTalk/Food");
fi.firstTimeFillPath(getResources(), "PrivatePictures", Environment.getExternalStorageDirectory().toString() +"PrivatePictures");
Intent intent = new Intent(getApplicationContext(),MainMenuActivity.class);
intent.putExtra("dataStorePath",sdStoragePath);
startActivity(intent);
}
}
});
}}
My XML file
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/languagetext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="236dp"
android:text="Choose language" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/languagetext"
android:layout_alignRight="#+id/languagetext"
android:layout_below="#+id/languageGroup">
<RadioButton
android:id="#+id/norwegianRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Norwegian" />
<RadioButton
android:id="#+id/englishRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="English" />
</RadioGroup>
<TextView
android:id="#+id/internal_sd"
android:layout_width="464dp"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="236dp"
android:text="Do you want to store the data to:" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:id="#+id/storageGroup">
<RadioButton
android:id="#+id/sdcardRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:checked="true"
android:text="SD card" />
<RadioButton
android:id="#+id/internalRadioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="Internal storage" />
</RadioGroup>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ok"
android:id="#+id/okBtn"
android:layout_gravity="bottom" />
To start off with, what element is assigned the id "#+id/languageGroup" since it doesn't appear to be declared in your XML

Android allow multi-touch on an activity

I am trying to allow the user to put a ring on the circle on the screen and then press the larger button so that the circle goes to the next ring size.
Everything work fines when no ring is on the screen.
However when a ring it on the screen no other touches are called and the buttons and the seekbar does not work.
I'm new in android and i haven't came across this requirement before. Is there a way I can allow multi-touch gestures on the activity or a way to ignore touches on that specific layout?
XML File
<?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:background="#color/White"
android:splitMotionEvents="false"
>
<TextView
android:id="#+id/us"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<TextView
android:id="#+id/uklbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uslbl"
android:padding="#dimen/standard_margin"
android:text="UK Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<TextView
android:id="#+id/uk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/uklbl"
android:layout_alignBottom="#+id/uklbl"
android:layout_toRightOf="#+id/uklbl"
android:padding="#dimen/standard_margin"
android:text="size"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/pressed_gemporia" />
<ImageView
android:id="#+id/ci"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true" />
<TextView
android:id="#+id/uslbl"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#+id/uk"
android:gravity="left"
android:padding="#dimen/standard_margin"
android:text="US Size:"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#color/Black" />
<SeekBar
android:id="#+id/seekbar"
android:progressDrawable="#drawable/red_scrubber_progress"
android:thumb="#drawable/red_scrubber_control"
android:max="8"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/divider" />
<View
android:id="#+id/divider"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_alignParentLeft="true"
android:layout_below="#+id/uklbl"
android:layout_marginTop="18dp"
android:background="#color/pressed_gemporia" />
<TextView
android:id="#+id/sizes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:padding="#dimen/standard_margin"
android:layout_below="#+id/seekbar"
android:text="TextView" android:textColor="#color/pressed_gemporia" />
<Button
android:id="#+id/right"
android:layout_width="100dp"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:background="#color/White"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/left"
android:text="Larger" />
<Button
android:id="#+id/left"
android:layout_width="100dp"
android:background="#color/White"
android:textColor="#color/pressed_gemporia"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:text="Smaller" />
<ImageView
android:id="#+id/ring"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/ci"
android:layout_centerHorizontal="true"
android:src="#drawable/j" />
Java Code
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.ring_sizes);
left = (Button)findViewById(R.id.left);
right = (Button)findViewById(R.id.right);
us = (TextView) findViewById(R.id.us);
uk = (TextView) findViewById(R.id.uk);
ci = (ImageView)findViewById(R.id.ci);
ring = (ImageView)findViewById(R.id.ring);
sizes.add(R.drawable.j);
sizes.add(R.drawable.l);
sizes.add(R.drawable.n);
sizes.add(R.drawable.p);
sizes.add(R.drawable.r);
sizes.add(R.drawable.t);
sizes.add(R.drawable.v);
sizes.add(R.drawable.x);
sizes.add(R.drawable.z);
USsizes.add("5");
USsizes.add("6");
USsizes.add("7");
USsizes.add("8");
USsizes.add("9");
USsizes.add("10");
USsizes.add("11");
USsizes.add("12");
USsizes.add("13");
UKsizes.add("J-K");
UKsizes.add("L-M");
UKsizes.add("N-O");
UKsizes.add("P-Q");
UKsizes.add("R-S");
UKsizes.add("T-U");
UKsizes.add("V-W");
UKsizes.add("X-Y");
UKsizes.add("Z+");
color = (getBaseContext().getResources().getColor(R.color.pressed_gemporia));
value = (TextView) findViewById(R.id.sizes);
seekbar = (SeekBar) findViewById(R.id.seekbar);
seekbar.getProgressDrawable().setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY));
value.setText("UK Size : "+UKsizes.get(0) + " - US Size: " + USsizes.get(0));
setUpViews();
seekbar.setOnSeekBarChangeListener( new OnSeekBarChangeListener()
{
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser)
{
ring.setImageResource(sizes.get(progress));
us.setText(USsizes.get(progress));
uk.setText(UKsizes.get(progress));
counter=progress;
value.setText("UK Size : "+UKsizes.get(progress) + " - US Size: " + USsizes.get(progress));
}
public void onStartTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
public void onStopTrackingTouch(SeekBar seekBar)
{
// TODO Auto-generated method stub
}
});
}
public void setUpViews(){
ring.setImageResource(sizes.get(counter));
us.setText(USsizes.get(counter));
uk.setText(UKsizes.get(counter));
right.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(UKsizes.size()>counter+1){
ring.setImageResource(sizes.get(counter+1));
seekbar.setProgress(counter+1);
}
}
});
left.setOnClickListener(new View.OnClickListener()
{
#Override
public void onClick(View view)
{
if(counter!=0){
ring.setImageResource(sizes.get(counter));
seekbar.setProgress(counter-1);
} }
});
}
}
There is a way to ignore touches in particular layout,for that you should add
android:splitMotionEvents="false"
in your layout . You can refer answers from thie following link
https://stackoverflow.com/questions/12777435/disable-multi-finger-touch-in-my-app

Categories

Resources