Saving the state of checkboxes - android

I have problem with my application. I have an application with checkboxes. How can i save them?
My layout is:
<?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:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Switzerland" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="35dp"
android:textSize="14dp"
android:textColor="#545454"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Bern" />
<CheckBox
android:id="#+id/itemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:layout_alignParentRight="true"
android:gravity="right" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="80dp"
android:textSize="20dp"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Germany" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="105dp"
android:textSize="14dp"
android:textColor="#545454"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Berlin" />
<CheckBox
android:id="#+id/itemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="90dp"
android:layout_alignParentRight="true"
android:gravity="right" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="150dp"
android:textSize="20dp"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Great Britain" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="175dp"
android:textSize="14dp"
android:textColor="#545454"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="London" />
<CheckBox
android:id="#+id/itemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="160dp"
android:layout_alignParentRight="true"
android:gravity="right" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="220dp"
android:textSize="20dp"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="France" />
<TextView
android:id="#+id/lstvw_textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginTop="245dp"
android:textSize="14dp"
android:textColor="#545454"
android:layout_toLeftOf="#+id/itemCheckBox"
android:padding="8dp"
android:text="Paris" />
<CheckBox
android:id="#+id/itemCheckBox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="230dp"
android:layout_alignParentRight="true"
android:gravity="right" />
</RelativeLayout>
And my main.class is:
package com.example.capitalcities;
import com.example.capitalcities.R;
import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.widget.Button;
import android.view.MenuItem;
import android.widget.ImageButton;
import android.view.View.OnClickListener;
public class MainActivity2 extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.settings);
}
#Override
public boolean onOptionsItemSelected(MenuItem item){
Intent myIntent = new Intent(getApplicationContext(), MainActivity.class);
startActivityForResult(myIntent, 0);
return true;
}
}
Do you now how to do this?
I hope you understand me, and i hope you could help me.

Use SharedPreferences to store your checkboxes as boolean.
Something like :
SharedPreferences sharedPreferences = PreferencesManager.getDefaultSharedPreferences(this);
checkBoxDummy.setChecked(sharedPreferences.getBoolean("checkBoxDummy", false));
To store values, use a listener. Something like :
checkBoxDummy.setOnCheckedChangeListener(new OnCheckedChangeListener() {
public void onCheckedChanged(CompoundButton buttonView,boolean isChecked) {
sharedPreferences.putBoolean("checkBoxDummy", isChecked);
}
});

Related

TextViews are showing unexpected paste option

In an Activity I have some textviews which includes multi-line and long-messages, the textviews also have vertical scroll in them, these text views also have long-click-listener on them. Now the problem is that when I click on any of the textviews it gives me paste option and it also pastes the text on it (if I click paste). I have tried to set android:editable="false" but it does not work. So Please help.
XML Code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:overScrollMode="never"
android:scrollbars="none"
android:id="#+id/helpActivityScroll_id">
<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.example.appdeveloper.appname.HelpActivity">
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpAppImage_id"
android:layout_alignParentTop="true"
android:layout_alignParentStart="true"
android:src="#drawable/app"
android:layout_marginTop="20dp"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpAppText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpAppImage_id"
android:layout_alignBottom="#+id/helpAppImage_id"
android:layout_toEndOf="#+id/helpAppImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpAppText_id"
android:id="#+id/helpAppPeopleSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpTrustedPeopleImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/trusted"
android:layout_below="#+id/helpAppPeopleSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpTrustedPeopleText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpTrustedPeopleImage_id"
android:layout_toEndOf="#+id/helpTrustedPeopleImage_id"
android:layout_alignBottom="#+id/helpTrustedPeopleImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpTrustedPeopleText_id"
android:id="#+id/helpPeopleRingSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpRingImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/ring"
android:layout_below="#+id/helpPeopleRingSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpRingText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpRingImage_id"
android:layout_toEndOf="#+id/helpRingImage_id"
android:layout_alignBottom="#+id/helpRingImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:layout_alignParentEnd="true"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpRingText_id"
android:id="#+id/helpRingLocationSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpLocationImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/location"
android:layout_below="#+id/helpRingLocationSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpLocationText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignTop="#+id/helpLocationImage_id"
android:layout_toEndOf="#+id/helpLocationImage_id"
android:layout_alignBottom="#+id/helpLocationImage_id"
android:layout_alignParentEnd="true"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical" />
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpLocationText_id"
android:id="#+id/helpLocationPictureSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpPictureImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/picture"
android:layout_below="#+id/helpLocationPictureSeparator_id"
android:layout_marginLeft="5dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpPictureText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/helpPictureImage_id"
android:layout_toEndOf="#+id/helpPictureImage_id"
android:layout_alignBottom="#+id/helpPictureImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical"/>
<View
android:layout_width="fill_parent"
android:layout_height="1dp"
android:background="#ff003b"
android:layout_below="#+id/helpPictureText_id"
android:id="#+id/helpPictureSimSeparator_id"
android:layout_marginTop="20dp"
android:layout_alignParentEnd="true"
android:layout_alignParentStart="true"
android:layout_marginBottom="20dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="80dp"
android:id="#+id/helpSimImage_id"
android:layout_alignParentStart="true"
android:src="#drawable/sim"
android:layout_below="#+id/helpPictureSimSeparator_id"
android:layout_marginLeft="5dp"
android:layout_marginBottom="20dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Text"
android:id="#+id/helpSimText_id"
android:inputType="textLongMessage|textMultiLine"
android:layout_alignParentEnd="true"
android:layout_alignTop="#+id/helpSimImage_id"
android:layout_toEndOf="#+id/helpSimImage_id"
android:layout_alignBottom="#+id/helpSimImage_id"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:gravity="center_vertical|left"
android:scrollbars="vertical"/>
</RelativeLayout>
</ScrollView>
JAVA Code:
package com.example.appdeveloper.appname;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.method.ScrollingMovementMethod;
import android.view.MotionEvent;
import android.view.View;
import android.widget.ScrollView;
import android.widget.TextView;
public class HelpActivity extends AppCompatActivity implements View.OnLongClickListener, View.OnTouchListener {
private ScrollView helpActivityScrollView;
private TextView helpApp;
private TextView helpTrustedPeople;
private TextView helpRing;
private TextView helpLocation;
private TextView helpPicture;
private TextView helpSim;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_help);
ActionBar actionBar = getSupportActionBar();
actionBar.setBackgroundDrawable(new ColorDrawable(Color.parseColor("#ff003b")));
actionBar.setTitle("Help");
helpActivityScrollView = ((ScrollView)findViewById(R.id.helpActivityScroll_id));
helpActivityScrollView.setOnTouchListener(this);
helpApp = (TextView)findViewById(R.id.helpAppText_id);
helpApp.setMovementMethod(new ScrollingMovementMethod());
helpApp.setOnLongClickListener(this);
helpTrustedPeople = (TextView)findViewById(R.id.helpTrustedPeopleText_id);
helpTrustedPeople.setMovementMethod(new ScrollingMovementMethod());
helpTrustedPeople.setOnLongClickListener(this);
helpRing = (TextView)findViewById(R.id.helpRingText_id);
helpRing.setMovementMethod(new ScrollingMovementMethod());
helpRing.setOnLongClickListener(this);
helpLocation = (TextView)findViewById(R.id.helpLocationText_id);
helpLocation.setMovementMethod(new ScrollingMovementMethod());
helpLocation.setOnLongClickListener(this);
helpPicture = (TextView)findViewById(R.id.helpPictureText_id);
helpPicture.setMovementMethod(new ScrollingMovementMethod());
helpPicture.setOnLongClickListener(this);
helpSim = (TextView)findViewById(R.id.helpSimText_id);
helpSim.setMovementMethod(new ScrollingMovementMethod());
helpSim.setOnLongClickListener(this);
String appHelp = "log and multi line message 1";
helpApp.setText(appHelp);
String trustedPeopleHelp = "log and multi line message 2";
helpTrustedPeople.setText(trustedPeopleHelp);
String ringHelp = "log and multi line message 3";
helpRing.setText(ringHelp);
String locationHelp = "log and multi line message 4";
helpLocation.setText(locationHelp);
String pictureHelp = "log and multi line message 5";
helpPicture.setText(pictureHelp);
String simHelp = "log and multi line message 6";
helpSim.setText(simHelp);
}
#Override
public boolean onLongClick(View view) {
view.getParent().requestDisallowInterceptTouchEvent(true);
return false;
}
#Override
public boolean onTouch(View view, MotionEvent motionEvent) {
helpActivityScrollView.requestDisallowInterceptTouchEvent(false);
return false;
}
}
Add empty click listener for it which override default behaviour of textView. same thing you can apply for other textview like below :
helpSim.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
}
});
Hope these solve your problem.

Weird behavior on item click

I'm building an app that sends USSD commands to check for balance, etc.
The apps acts weirdly when I try to launch activities from item click, here from image button: I have to touch two times to launch an activity. I don't know what is wrong.
Have a look at my code:
MainActivity.java:
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.EditText;
import android.widget.ImageButton;
import android.widget.ImageView;
import android.widget.RelativeLayout;
public class MainActivity extends AppCompatActivity {
ImageView accountView;
ImageView activationsView;
ImageView servicesView;
ImageView othersView;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
public void openAccountView(View view){
accountView = (ImageView) findViewById(R.id.accountView);
accountView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, AccountActivity.class);
startActivity(i);
}
});
}
public void openActivationsView(View view){
activationsView = (ImageView) findViewById(R.id.activationsView);
activationsView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ActivationsActivity.class);
startActivity(i);
}
});
}
public void openServicesView(View view){
servicesView = (ImageView) findViewById(R.id.servicesView);
servicesView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent i = new Intent(MainActivity.this, ServicesActivity.class);
startActivity(i);
}
});
}
public void openOthersView(View view){
}
}
activity_main.xml:
<?xml version="1.0" encoding="utf-8" ?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#id/layout_dashboard_parent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#android:color/white">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:background="#color/c_dashboard_btn_quick_clean_color"
android:orientation="horizontal">
<Button
android:id="#+id/buttonCB"
style="#android:style/Widget.Material.Light.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="2dip"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_weight="2"
android:background="#color/c_main_back_ground_color"
android:elevation="7dp"
android:text="#string/check_balance"
tools:ignore="ButtonStyle"
tools:targetApi="lollipop" />
<Button
android:id="#+id/buttonLB"
style="#android:style/Widget.Material.Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="2dip"
android:layout_marginRight="2dip"
android:layout_marginStart="2dip"
android:layout_weight="2"
android:background="#color/c_main_back_ground_color"
android:elevation="7dp"
android:text="#string/load_balance"
tools:ignore="ButtonStyle"
tools:targetApi="lollipop" />
</LinearLayout>
<ScrollView
android:id="#id/main_scroll_view"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/webview_ads"
tools:ignore="UnknownIdInLayout">
<LinearLayout
android:id="#id/layout_dashboard_scroll_container"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="1">
<FrameLayout
android:id="#id/dashboard_alert_section"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:visibility="gone">
<include layout="#layout/dashboard_feature_tip_item" />
</FrameLayout>
<FrameLayout
android:id="#id/main_control_layout"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="345">
<FrameLayout
android:id="#id/dashboard_progress_bar"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="#dimen/dashboard_clean_progess_mar_top"
android:elevation="#dimen/dashboard_progressbar_elevation"
android:visibility="gone"
tools:ignore="UselessParent"
tools:targetApi="lollipop">
<ImageView
android:layout_width="#dimen/dashboard_progress_clean_all_image_dimension"
android:layout_height="#dimen/dashboard_progress_clean_all_image_dimension"
android:layout_gravity="center"
android:contentDescription=""
android:src="#drawable/btn_ram_checkbox"
tools:ignore="ContentDescription" />
<ProgressBar
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
</LinearLayout>
</ScrollView>
<RelativeLayout
android:id="#id/layout_main"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:background="#color/c_main_back_ground_color">
<RelativeLayout
android:id="#id/layout_account"
android:layout_width="#dimen/dashboard_feature_layout_width"
android:layout_height="#dimen/dashboard_feature_layout_height"
android:layout_marginEnd="#dimen/dashboard_feature_middle_margin"
android:layout_marginLeft="#dimen/dashboard_feature_leftmost_margin"
android:layout_marginRight="#dimen/dashboard_feature_middle_margin"
android:layout_marginStart="#dimen/dashboard_feature_leftmost_margin"
android:layout_marginTop="#dimen/dashboard_feature_top_margin"
android:background="#drawable/dashboard_bg_selector"
android:clickable="false"
android:elevation="6dp"
android:focusable="false"
tools:targetApi="lollipop">
<ImageView
android:id="#+id/accountView"
android:layout_width="130dip"
android:layout_height="130dip"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:adjustViewBounds="false"
android:background="#color/checkbox_button_color"
android:clickable="true"
android:contentDescription="#string/account"
android:cropToPadding="false"
android:onClick="openAccountView"
android:visibility="visible"
app:srcCompat="#drawable/account" />
<TextView
android:id="#+id/accountTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:gravity="center_vertical|center_horizontal|center"
android:text="#string/account"
android:textColor="#color/body_text_color"
android:textSize="18sp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/accountView"
android:paddingBottom="2dip"
android:paddingEnd="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingStart="2dip"
android:text="#string/account_detail"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#id/layout_activations"
android:layout_width="#dimen/dashboard_feature_layout_width"
android:layout_height="#dimen/dashboard_feature_layout_height"
android:layout_marginEnd="#dimen/dashboard_feature_rightmost_margin"
android:layout_marginLeft="#dimen/dashboard_feature_middle_margin"
android:layout_marginRight="#dimen/dashboard_feature_rightmost_margin"
android:layout_marginStart="#dimen/dashboard_feature_middle_margin"
android:layout_marginTop="#dimen/dashboard_feature_top_margin"
android:layout_toEndOf="#id/layout_account"
android:layout_toRightOf="#id/layout_account"
android:background="#drawable/dashboard_bg_selector"
android:clickable="false"
android:elevation="#dimen/dashboard_feature_bg_elevation"
android:focusable="false"
android:onClick="openActivationsView"
tools:targetApi="lollipop">
<ImageView
android:id="#+id/activationsView"
android:layout_width="130dip"
android:layout_height="130dip"
android:layout_alignParentEnd="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="false"
android:layout_centerHorizontal="true"
android:layout_centerInParent="true"
android:layout_centerVertical="true"
android:clickable="true"
android:contentDescription="#string/activations_packs"
android:onClick="openActivationsView"
app:srcCompat="#drawable/activations" />
<TextView
android:id="#+id/textView3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/activationsView"
android:elevation="7dp"
android:paddingBottom="2dip"
android:paddingEnd="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingStart="2dip"
android:text="#string/activations_detail"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp" />
<TextView
android:id="#+id/activationsTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:gravity="center_vertical|center_horizontal|center"
android:text="#string/activations_packs"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
<RelativeLayout
android:id="#id/layout_services"
android:layout_width="#dimen/dashboard_feature_layout_width"
android:layout_height="#dimen/dashboard_feature_layout_height"
android:layout_below="#id/layout_account"
android:layout_marginBottom="10dip"
android:layout_marginEnd="#dimen/dashboard_feature_middle_margin"
android:layout_marginLeft="#dimen/dashboard_feature_leftmost_margin"
android:layout_marginRight="#dimen/dashboard_feature_middle_margin"
android:layout_marginStart="#dimen/dashboard_feature_leftmost_margin"
android:layout_marginTop="#dimen/dashboard_feature_ram_security_top_margin"
android:background="#drawable/dashboard_bg_selector"
android:clickable="false"
android:elevation="5dp"
android:focusable="false"
android:onClick="openServicesView"
tools:targetApi="lollipop">
<TextView
android:id="#+id/servicesTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:gravity="center_vertical|center_horizontal|center"
android:text="#string/services"
android:textColor="#android:color/black"
android:textSize="18sp"
android:textStyle="bold" />
<ImageView
android:id="#+id/servicesView"
android:layout_width="130dip"
android:layout_height="130dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/services"
app:srcCompat="#drawable/services" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_below="#+id/servicesView"
android:paddingBottom="2dip"
android:paddingEnd="2dip"
android:paddingLeft="2dip"
android:paddingRight="2dip"
android:paddingStart="2dip"
android:text="#string/services_detail"
android:textAlignment="center"
android:textColor="#color/black"
android:textSize="12sp" />
</RelativeLayout>
<RelativeLayout
android:id="#id/layout_others"
android:layout_width="#dimen/dashboard_feature_layout_width"
android:layout_height="#dimen/dashboard_feature_layout_height"
android:layout_below="#id/layout_activations"
android:layout_marginBottom="10dip"
android:layout_marginEnd="#dimen/dashboard_feature_rightmost_margin"
android:layout_marginLeft="#dimen/dashboard_feature_middle_margin"
android:layout_marginRight="#dimen/dashboard_feature_rightmost_margin"
android:layout_marginStart="#dimen/dashboard_feature_middle_margin"
android:layout_marginTop="#dimen/dashboard_feature_ram_security_top_margin"
android:layout_toEndOf="#id/layout_services"
android:layout_toRightOf="#id/layout_services"
android:background="#drawable/dashboard_bg_selector"
android:clickable="false"
android:elevation="#dimen/dashboard_feature_bg_elevation"
android:focusable="false"
tools:targetApi="lollipop">
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="31dp"
android:text="#string/other_detail"
android:textColor="#color/black"
android:textSize="12sp" />
<ImageView
android:id="#+id/otherView"
android:layout_width="130dip"
android:layout_height="130dip"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:contentDescription="#string/other"
app:srcCompat="#drawable/help" />
<TextView
android:id="#+id/otherTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="14dp"
android:clickable="true"
android:gravity="center_vertical|center_horizontal|center"
android:onClick="openOthersView"
android:text="#string/other"
android:textColor="#color/black"
android:textSize="18sp"
android:textStyle="bold" />
</RelativeLayout>
</RelativeLayout>
</RelativeLayout>
You are calling openAccountView method by onClick imageView by this:
android:onClick="openAccountView"
So, no need to add onClicklistener to your imageView.
Remove onClicklistener in openAccountView, Use the below code :
public void openAccountView(View view){
Intent i = new Intent(MainActivity.this, AccountActivity.class);
startActivity(i);
}
Hope this helps.

how to get cross button/image in custom dialog box border

I have used cutsom dialog box in my MainActivity for popup screen.I have added cross button to close
the popup screen. here in my code, that cross button is showing inside
the popup screen.
Now what i want is it has to show at the border of the popup screen.
please help me to get this..
Below is my code..any help would be appreciated...thanks in advance..
Java File
HomePage.java
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.Dialog;
import android.content.Context;
import android.content.Intent;
import android.graphics.Point;
import android.os.Bundle;
import android.view.Display;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.TextView;
import android.support.v4.app.DialogFragment;
public class HomePage extends Activity {
final Context context = this;
Button b1;
Button b2;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home_page);
b1 = (Button) findViewById(R.id.button6);
b2 = (Button) findViewById(R.id.button7);
b2.setOnClickListener(new OnClickListener(){
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
Intent intent = new Intent(HomePage.this,RegisterPage.class);
startActivity(intent);
}
});
b1.setOnClickListener(new OnClickListener() {
#SuppressLint("NewApi")
#Override
public void onClick(View arg0) {
// custom dialog
final Dialog dialog = new Dialog(context);
dialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
dialog.setContentView(R.layout.activity_login_page);
WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = wm.getDefaultDisplay(); // getting the screen size of device
Point size = new Point();
display.getSize(size);
int width = size.x - 20; // Set your heights
int height = size.y - 80; // set your widths
WindowManager.LayoutParams lp = new WindowManager.LayoutParams();
lp.copyFrom(dialog.getWindow().getAttributes());
lp.width = width;
lp.height = height;
dialog.getWindow().setAttributes(lp);
dialog.show();
ImageView image = (ImageView) dialog.findViewById(R.id.cancel_btn);
image.setImageResource(R.drawable.cancel2);
image.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
// TODO Auto-generated method stub
dialog.dismiss();
}
});
Button dialogButton = (Button) dialog.findViewById(R.id.button1);
dialogButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
//dialog.dismiss();
Intent intent = new Intent(HomePage.this,CategoryPage.class);
startActivity(intent);
}
});
dialog.show();
}
});
}
}
XML File
activity_home_page.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:background="#fff"
tools:context=".MainActivity" >
<LinearLayout android:id="#+id/header"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#fff"
android:paddingLeft="0dp"
android:paddingRight="0dp"
android:paddingTop="5dip"
android:paddingBottom="5dip">
<ImageView
android:id="#+id/imageView1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="0dp"
android:src="#drawable/miiskylogo" />
</LinearLayout>
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_below="#+id/header" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="163dp"
android:orientation="vertical"
android:paddingBottom="0dp"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" >
<Button
android:id="#+id/button6"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="32dp"
android:drawableLeft="#drawable/lock"
android:text="Login with SVAPP" />
<Button
android:id="#+id/button7"
android:layout_width="230dp"
android:layout_height="50dp"
android:background="#00b0ff"
android:layout_weight="0.1666"
android:textSize="18dp"
android:textColor="#fff"
android:paddingLeft="3dp"
android:layout_gravity="center"
android:layout_marginTop="15dp"
android:drawableLeft="#drawable/regis"
android:text="Register with SVAPP" />
</LinearLayout>
</ScrollView>
</RelativeLayout>
activity_login_page.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:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/cancel2" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/miiskylogo" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent">
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginTop="190dp"
android:layout_marginRight="15dp"
android:background="#drawable/loginedit"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textStyle="bold"
android:textColorHint="#bdbdbd"
android:textSize="13dp" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/loginbutton"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp"
>
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp">
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="280dp"
android:padding="10dp"
android:layout_marginRight="20dp"
android:text="Lorem Ipsum dolor sit amet,"
android:background="#drawable/loginedit"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
I want cross button something like the image below.
Click Here
Try this solution:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#fff"
tools:context="com.example.miiskyproject.Login" >
<LinearLayout
android:id="#+id/cancel_layuot"
android:layout_width="match_parent"
android:gravity="right"
android:background="#android:color/transparent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/cancel_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<ImageView
android:id="#+id/imageView1"
android:layout_width="130dp"
android:layout_height="90dp"
android:layout_below="#+id/cancel_layuot"
android:layout_centerHorizontal="true"
android:layout_marginTop="34dp"
android:src="#drawable/left_arrow" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot" >
<EditText
android:id="#+id/editText1"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginLeft="15dp"
android:layout_marginRight="10dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="User Name"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" >
<requestFocus />
</EditText>
<EditText
android:id="#+id/editText2"
android:layout_width="80dp"
android:layout_height="35dp"
android:layout_marginRight="15dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="6"
android:hint="Password"
android:inputType="textPassword"
android:padding="8dp"
android:textColor="#000"
android:textColorHint="#bdbdbd"
android:textSize="13dp"
android:textStyle="bold" />
<Button
android:id="#+id/button1"
android:layout_width="70dp"
android:layout_height="35dp"
android:layout_marginRight="20dp"
android:layout_marginTop="190dp"
android:background="#drawable/ic_launcher"
android:ems="7"
android:text="Login"
android:textColor="#fff"
android:textSize="12dp" />
</LinearLayout>
<LinearLayout
android:id="#+id/panelInsurance7"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="225dp"
android:text="Forget Your Password?"
android:textSize="13dp"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:id="#+id/linear1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_below="#+id/cancel_layuot"
android:layout_marginLeft="15dp"
android:layout_marginTop="10dp" >
<TextView
android:id="#+id/textView2"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_marginTop="280dp"
android:background="#drawable/ic_launcher"
android:padding="10dp"
android:text="Lorem Ipsum dolor sit amet,"
android:textSize="18dp"
android:textStyle="bold" />
</LinearLayout>
</RelativeLayout>
You will see something like this:
Just replace image ic_launcher with the appropriated image.

Inflating layout in android

Hi i want to inflate an xml layout in another layout. Iam doing it correctly but it is not properly coming. Because the page in which i inflating the layout contains 2 relative layouts. I give different id'sandroid:id="#+id/stocklist" and android:id="#+id/gifts" for the two relative layouts. The stocklist layout contains a + button and when we click the + button it has to inflate the layout below to it.When iam inflating another layout inside the stocklist layout, the inflated xml is not properly alligned and it is not coming below the parent layout. Please help me if anybody knows. I added my code and layout here.
My parent layout code:
<?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" >
<ScrollView
android:id="#+id/ScrollView01"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="704dp"
android:orientation="vertical" >
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView8"
android:layout_alignBottom="#+id/textView8"
android:layout_toRightOf="#+id/textView7"
android:text="Quantity"
android:textAppearance="?android:attr/textAppearanceSmall" />
<RelativeLayout
android:id="#+id/stocklist"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView8"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/spinproducts"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/editText1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="#+id/spinproducts"
android:layout_marginLeft="146dp"
android:layout_toRightOf="#+id/spinproducts"
android:ems="10"
android:inputType="number"
android:hint="Qty" />
<CheckBox
android:id="#+id/checkBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_marginRight="136dp"
android:layout_toLeftOf="#+id/spindetail" />
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="11dp"
android:onClick="onAddNewClicked"
android:text="+" />
<Spinner
android:id="#+id/spindetail"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="50dp"
android:layout_toLeftOf="#+id/button1"
android:ems="10"
android:hint="Remarks" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/gifts"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView12"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/spingift"
android:layout_width="375dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/etgiftqty"
android:layout_width="500dp"
android:layout_height="40dp"
android:layout_alignBottom="#+id/spingift"
android:layout_marginLeft="33dp"
android:layout_toRightOf="#+id/spingift"
android:ems="10"
android:inputType="number"
android:hint="Qty" >
</EditText>
<Button
android:id="#+id/button1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:text="+" />
</RelativeLayout>
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/gifts"
android:layout_marginTop="33dp"
android:text="Call Outcome :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView14"
android:layout_below="#+id/textView14"
android:layout_marginTop="20dp"
android:text="Follow Up:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/stocklist"
android:layout_marginLeft="10dp"
android:layout_marginTop="16dp"
android:text="Gifts / Others :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView12"
android:layout_below="#+id/textView7"
android:layout_marginTop="12dp"
android:text="Product"
android:textAppearance="?android:attr/textAppearanceSmall" />
<EditText
android:id="#+id/editText3"
android:layout_width="match_parent"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView13"
android:layout_alignRight="#+id/editText8"
android:layout_below="#+id/textView13"
android:layout_marginTop="12dp"
android:ems="10" >
</EditText>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner4"
android:layout_alignParentBottom="true"
android:layout_marginLeft="13dp"
android:text="Dr.Not Available" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText6"
android:layout_alignParentBottom="true"
android:layout_marginLeft="16dp"
android:text="Add Call" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="51dp"
android:layout_toRightOf="#+id/button3"
android:text="Cancel" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/spinner1"
android:layout_toLeftOf="#+id/textView9"
android:text="In Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<MultiAutoCompleteTextView
android:id="#+id/multiAutoCompleteTextView1"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/spinner3"
android:layout_marginRight="17dp"
android:ems="10" >
</MultiAutoCompleteTextView>
<EditText
android:id="#+id/editText8"
android:layout_width="130dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText7"
android:layout_alignBottom="#+id/editText7"
android:layout_alignRight="#+id/multiAutoCompleteTextView1"
android:ems="10"
android:hint="Notes">
</EditText>
<EditText
android:id="#+id/editText6"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/spinner3"
android:layout_alignTop="#+id/spinner4"
android:ems="10"
android:hint="Amount">
</EditText>
<EditText
android:id="#+id/editText7"
android:layout_width="120dp"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/editText6"
android:layout_alignBottom="#+id/editText6"
android:layout_marginRight="10dp"
android:layout_toLeftOf="#+id/editText8"
android:ems="10"
android:hint="date"/>
<TextView
android:id="#+id/textView17"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView15"
android:layout_toLeftOf="#+id/editText7"
android:text="Spon.Req"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/spinner1"
android:text="Detailing and Samples Dispensed :"
android:textAppearance="?android:attr/textAppearanceLarge" />
<Spinner
android:id="#+id/spinner1"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignLeft="#+id/textView7"
android:layout_below="#+id/textView2" />
<TextView
android:id="#+id/textView14"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText3"
android:layout_below="#+id/editText3"
android:layout_marginTop="20dp"
android:text="Schedule Follow"
android:textAppearance="?android:attr/textAppearanceLarge" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/spinner1"
android:layout_below="#+id/textView1"
android:layout_marginTop="12dp"
android:text="Location of Visit"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_alignParentTop="true"
android:text="Doctor Name"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#008000"
android:textSize="35dp"
android:textStyle="bold" />
<EditText
android:id="#+id/editText4"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_alignBaseline="#+id/textView15"
android:layout_alignBottom="#+id/textView15"
android:layout_alignLeft="#+id/editText5"
android:ems="10" >
</EditText>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/multiAutoCompleteTextView1"
android:layout_marginLeft="41dp"
android:layout_toRightOf="#+id/button4"
android:text="Work with"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/textView9"
android:layout_alignBottom="#+id/textView9"
android:layout_marginRight="38dp"
android:layout_toLeftOf="#+id/textView17"
android:text="Detailed"
android:textAppearance="?android:attr/textAppearanceSmall" />
<Spinner
android:id="#+id/spinner2"
android:layout_width="123dp"
android:layout_height="38dp"
android:layout_alignLeft="#+id/textView9"
android:layout_alignTop="#+id/textView5"
android:layout_marginLeft="22dp" />
<EditText
android:id="#+id/editText5"
android:layout_width="wrap_content"
android:layout_height="40dp"
android:layout_below="#+id/editText4"
android:layout_marginLeft="29dp"
android:layout_marginTop="11dp"
android:layout_toRightOf="#+id/spinner1"
android:ems="10" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/editText5"
android:layout_alignBottom="#+id/editText5"
android:layout_alignLeft="#+id/textView15"
android:text="Follow Up Actions:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/stocklist"
android:layout_alignLeft="#+id/editText7"
android:layout_marginLeft="25dp"
android:text="Discussion Topics"
android:textAppearance="?android:attr/textAppearanceSmall" />
<TextView
android:id="#+id/textView6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/textView10"
android:layout_below="#+id/textView2"
android:text="Out Time:"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Spinner
android:id="#+id/spinner3"
android:layout_width="123dp"
android:layout_height="38dp"
android:layout_above="#+id/textView7"
android:layout_toLeftOf="#+id/textView11" />
<Spinner
android:id="#+id/spinner4"
android:layout_width="145dp"
android:layout_height="40dp"
android:layout_alignRight="#+id/textView10"
android:layout_alignTop="#+id/editText5" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/spinner3"
android:layout_alignLeft="#+id/spinner4"
android:text="Duration of Visit"
android:textAppearance="?android:attr/textAppearanceMedium" />
</RelativeLayout>
</ScrollView>
</RelativeLayout>
Layout which has to be inflated:
<?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="50dp"
android:orientation="horizontal" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView8"
android:layout_below="#+id/textView8"
android:layout_marginTop="11dp"
android:orientation="vertical" >
<Spinner
android:id="#+id/inflatespinproducts"
android:layout_width="175dp"
android:layout_height="40dp"
android:layout_marginTop="13dp"
android:ems="10"
android:hint="Stocklist Name" >
</Spinner>
<EditText
android:id="#+id/inflateeditText1"
android:layout_width="150dp"
android:layout_height="40dp"
android:layout_alignTop="#+id/inflatespinproducts"
android:layout_marginLeft="146dp"
android:layout_toRightOf="#+id/inflatespinproducts"
android:ems="10"
android:inputType="number"
android:hint="Qty" />
<CheckBox
android:id="#+id/inflatecheckBox1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/inflateeditText1"
android:layout_marginRight="136dp"
android:layout_toLeftOf="#+id/inflatespindetail" />
<Button
android:id="#+id/inflatebutton1"
style="?android:attr/buttonStyleSmall"
android:layout_width="40dp"
android:layout_height="45dp"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginRight="11dp"
android:onClick="onDeleteClicked"
android:text="-" />
<Spinner
android:id="#+id/inflatespindetail"
android:layout_width="180dp"
android:layout_height="40dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="50dp"
android:layout_toLeftOf="#+id/inflatebutton1"
android:ems="10"
android:hint="Remarks" />
</RelativeLayout>
</LinearLayout>
After inflating the layout my page looks like:
http://i.stack.imgur.com/SOWBJ.png">
My source code:
package abts.medismo.e_detailing;
import abts.medismo.e_detailing.Model.Spinmodel;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.CheckBox;
import android.widget.EditText;
import android.widget.MultiAutoCompleteTextView;
import android.widget.RelativeLayout;
import android.widget.Spinner;
import android.widget.TextView;
public class addcall extends Activity {
CheckBox chkdetailed;
TextView txtdocname, txtdisctopic;
MultiAutoCompleteTextView autoWorkwith;
Spinner spinlocation, intime, outtime, spinproducts, spingift, spindetail,
spinSponsorship;
String docid, docname, addid, addname, straddid, straddname, spaddid,
spaddname, dbcatid, dbcatname;
String strcatid, strcatname, spcatid, spcatname;
String spinlocationvalue, spingiftvalue, spinintimevalue, spinouttimevalue,
spinproductvalue, spinworkwithvalue, spindetailvalue,
spinsponsorshipvalue;
Intent bgIntent;
EditText etprodqty,etgiftqty;
RelativeLayout relStocklist;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.dupaddcall);
autoWorkwith = (MultiAutoCompleteTextView) findViewById(R.id.multiAutoCompleteTextView1);
autoWorkwith
.setTokenizer(new MultiAutoCompleteTextView.CommaTokenizer());
etprodqty=(EditText)findViewById(R.id.editText1);
etgiftqty=(EditText)findViewById(R.id.etgiftqty);
relStocklist=(RelativeLayout)findViewById(R.id.stocklist);
spinlocation = (Spinner) findViewById(R.id.spinner1);
spindetail = (Spinner) findViewById(R.id.spindetail);
spinSponsorship = (Spinner) findViewById(R.id.spinner4);
chkdetailed = (CheckBox) findViewById(R.id.checkBox1);
chkdetailed.setChecked(true);
intime = (Spinner) findViewById(R.id.spinner2);
outtime = (Spinner) findViewById(R.id.spinner3);
spinproducts = (Spinner) findViewById(R.id.spinproducts);
spingift = (Spinner) findViewById(R.id.spingift);
txtdocname = (TextView) findViewById(R.id.textView1);
txtdisctopic = (TextView) findViewById(R.id.textView11);
spindetail.setEnabled(false);
bgIntent = getIntent();
docid = bgIntent.getStringExtra("docid");
docname = bgIntent.getStringExtra("docname");
txtdocname.setText(docname);
DatabaseHandler dbh = new DatabaseHandler(addcall.this);
SQLiteDatabase db = dbh.getWritableDatabase();
addid = null;
addname = null;
}
public void onAddNewClicked(View v) {
inflateEditRow(null);
//v.setVisibility(View.VISIBLE);
}
private void inflateEditRow(String name) {
LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
final View rowView = inflater.inflate(R.layout.inflateaddproduct, null);
// A TextWatcher to control the visibility of the "Add new" button and
// handle the exclusive empty view.
// Inflate at the end of all rows but before the "Add new" button
relStocklist.addView(rowView, relStocklist.getChildCount());
}
public void onDeleteClicked(View v) {
relStocklist.removeView((View) v.getParent());
}
public void onBackPressed() {
super.onBackPressed();
Intent intent = new Intent(addcall.this, DCR.class);
intent.putExtra("planid", bgIntent.getStringExtra("planid"));
intent.putExtra("tourdate", bgIntent.getStringExtra("tourdate"));
final int result = 1;
startActivityForResult(intent, result);
finish();
}
}
You should change your relative stocklist layout to a linear layout, so the inflated layouts automatically arrange below each other.
<LinearLayout
android:id="#+id/stocklist"
android:orientation="vertical"
... >
...
</LinearLayout>

Starting Activity via Intent is slow / shows considerable delay - why?

I have a very simple MainActivity, and from that Activity I start the other Activity (with theme Dialog so it floats on top of the MainActivity.
The problem is that there is always a delay before the second Activity show up. I'd say it takes almost 1 second for it to show, and there is no code at all in second Activity. The only code in the second Activity is this:
package MyPackage;
import android.app.Activity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.TextView;
public class JobViewActivity extends Activity {
#Override
protected void onCreate(android.os.Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.jobview);
}
#Override
protected void onResume() {
super.onResume();
}
}
The MainActivity has a ListView with Nodes, and there is a click listener connected to the ListView in the onCreate like this:
public void onCreate(Bundle savedInstanceState)
{
requestWindowFeature(Window.FEATURE_NO_TITLE);
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
_nodeRowAdapter = new NodeRowAdapter(this, _nodes);
listView = (ListView)findViewById(R.id.ListViewNodes);
listView.setAdapter(_nodeRowAdapter);
listView.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
Intent i = new Intent(getApplicationContext(), JobViewActivity.class);
startActivity(i);
}
});
But when the ListItem is pressed, and the Click listener is triggered, it takes about 1 second to show the "popup".
The layout isn't very advanced in the popup. Here is the layout:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:weightSum="1"
android:stretchColumns="1" android:orientation="vertical">
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:stretchColumns="1" android:layout_height="wrap_content" android:id="#+id/tableLayout1">
<TableRow>
<TextView
android:text="Id: "
android:padding="10dip"/>
<TextView
android:text="Ext id: "
android:gravity="right"
android:padding="10dip" />
</TableRow>
</TableLayout>
<RelativeLayout android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:id="#+id/relativeLayout1">
<LinearLayout android:id="#+id/linearLayout1" android:layout_width="fill_parent" android:layout_height="wrap_content" android:background="#E7F3F1">
<Button android:text="Start" android:id="#+id/button1" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_green"></Button>
<Button android:text="Bom" android:id="#+id/button2" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_red"></Button>
<Button android:text="Mer" android:id="#+id/button3" style="#style/ButtonText" android:layout_weight="1" android:background="#drawable/button_yellow"></Button>
<Button android:text="Nav" android:id="#+id/button4" style="#style/ButtonText" android:layout_weight="1"></Button>
</LinearLayout>
</RelativeLayout>
<RelativeLayout android:layout_height="fill_parent" android:layout_width="fill_parent" android:layout_below="#+id/tableLayout1" android:layout_alignParentLeft="true" android:layout_above="#+id/relativeLayout1" android:padding="6dip">
<TextView style="#style/JobViewHeader" android:id="#+id/textView1" android:text="Something: "></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView2" android:text="Something: " android:layout_below="#+id/textView1"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView3" android:layout_marginTop="16dp" android:text="Kund: " android:layout_below="#+id/TextView2"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView4" android:text="Something: " android:layout_below="#+id/TextView3"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView5" android:text="Something: " android:layout_below="#+id/TextView4"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView6" android:text="Something: " android:layout_below="#+id/TextView5"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView7" android:text="Something: " android:layout_below="#+id/TextView6"></TextView>
<TextView style="#style/JobViewHeader" android:id="#+id/TextView8" android:layout_marginTop="20dp" android:text="Something: " android:layout_below="#+id/TextView7"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/textView1" android:layout_alignBottom="#+id/textView1" android:layout_toRightOf="#+id/textView1" android:id="#+id/textViewPickuptime"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView2" android:layout_alignBottom="#+id/TextView2" android:layout_toRightOf="#+id/TextView2" android:id="#+id/textViewPickupAddress"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView4" android:layout_toRightOf="#+id/TextView3" android:id="#+id/textViewCustomer"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView4" android:layout_alignBottom="#+id/TextView4" android:layout_toRightOf="#+id/TextView4" android:id="#+id/textViewNbrOfPassengers"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_above="#+id/TextView6" android:layout_toRightOf="#+id/TextView5" android:id="#+id/textViewRoutine"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView6" android:layout_alignBottom="#+id/TextView6" android:layout_toRightOf="#+id/TextView6" android:id="#+id/textViewServiceFee"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_alignBaseline="#+id/TextView7" android:layout_alignBottom="#+id/TextView7" android:layout_toRightOf="#+id/TextView7" android:id="#+id/textViewHelp"></TextView>
<TextView android:layout_height="wrap_content" android:text="TextView" android:layout_width="wrap_content" android:layout_below="#+id/TextView8" android:layout_alignLeft="#+id/TextView8" android:id="#+id/textViewExtra"></TextView>
</RelativeLayout>
</RelativeLayout>
Im not sure what else to tell you, there isnt much more too it.
Im testing on a device, Samsung Galaxy S2.

Categories

Resources