android tabs repeated content - java

I've set up a tab host and defined 5 tabs both in the xml file and the corresponding java class file. I added some fields for tab 1 and a test field for tab 2 but all I see in each tab is the repeated content from tab 1. Has anyone come across this before? code is pasted below.
Thanks
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspection);
TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec = tabHost.newTabSpec("Part1");
tabSpec.setContent(R.id.tabPart1);
tabSpec.setIndicator("1");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part2");
tabSpec.setContent(R.id.tabPart2);
tabSpec.setIndicator("2");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part3");
tabSpec.setContent(R.id.tabPart3);
tabSpec.setIndicator("3");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part4");
tabSpec.setContent(R.id.tabPart4);
tabSpec.setIndicator("4");
tabHost.addTab(tabSpec);
tabHost.newTabSpec("Part5");
tabSpec.setContent(R.id.tabPart5);
tabSpec.setIndicator("5");
tabHost.addTab(tabSpec);
}
and the xml code:
<TabHost
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/tabHost"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></TabWidget>
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:id="#+id/tabPart1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/Id"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Global Unique ID" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/jobNum"
android:hint="Job Number"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Required?"
android:id="#+id/req"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/material"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Material" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/shape"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp"
android:hint="Shape" />
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/size"
android:hint="Size (mm)"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:id="#+id/LvlCollectGp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collect Now?"
android:id="#+id/collectNow"
android:hint="Collect Now?" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Collect Later?"
android:id="#+id/collectLtr" />
</RadioGroup>
<EditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:ems="10"
android:id="#+id/lvl"
android:hint="Level (m)"
android:layout_marginLeft="5sp"
android:layout_marginTop="10sp"
android:layout_marginRight="5sp" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabPart2"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/test"
android:hint="Test" />
</LinearLayout>
<LinearLayout
android:id="#+id/tabPart3"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="#+id/tabPart4"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
<LinearLayout
android:id="#+id/tabPart5"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"></LinearLayout>
</FrameLayout>
</LinearLayout>
</TabHost>

try this code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_inspection);
TabHost tabHost = (TabHost)findViewById(R.id.tabHost);
tabHost.setup();
TabHost.TabSpec tabSpec1 = tabHost.newTabSpec("Part1");
tabSpec1.setContent(R.id.tabPart1);
tabSpec1.setIndicator("1");
tabHost1.addTab(tabSpec1);
TabHost.TabSpec tabSpec2 = tabHost.newTabSpec("Part2");
tabSpec2.setContent(R.id.tabPart2);
tabSpec2.setIndicator("2");
tabHost2.addTab(tabSpec2);
TabHost.TabSpec tabSpec3 = tabHost.newTabSpec("Part3");
tabSpec3.setContent(R.id.tabPart3);
tabSpec3.setIndicator("3");
tabHost3.addTab(tabSpec3);
TabHost.TabSpec tabSpec4 = tabHost.newTabSpec("Part4");
tabSpec4.setContent(R.id.tabPart4);
tabSpec4.setIndicator("4");
tabHost4.addTab(tabSpec4);
TabHost.TabSpec tabSpec5 = tabHost.newTabSpec("Part5");
tabSpec5.setContent(R.id.tabPart5);
tabSpec5.setIndicator("5");
tabHost5.addTab(tabSpec5);
}

Related

Truecaller like alert dialog in dart

I am trying to implement a true caller like alert dialog in flutter. Since I am very new to flutter+dart, I was looking for any out of the box implementation. So far I have found system_alert_window but this creates the alert dialogue in JAVA and uses platform channels to communicate with it. My question is that if it's possible to do this is pure flutter+dart.
I do not know if this kind of dialogues has any special names, also in truecaller the dialogue is shown regardless the app is running or not. Can anyone provide some pointers?
Thanks
No you can't do with flutter
You can only go with Java.
Flollow the steps
your project > android > app > src > main > AndroidManifest.xml
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
add this permission on your Androidmanifest.xml file
after adding the permission add the below receiver class
<receiver android:name=".CallReceiver"
android:enabled="true"
android:permission="android.permission.BIND_JOB_SERVICE"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.PHONE_STATE" />
</intent-filter>
</receiver>
the receiver class
ServiceReceiver.Java
public class ServiceReceiver extends BroadcastReceiver {
#Override
public void onReceive(final Context context, Intent intent) {
TelephonyManager telephony = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
telephony.listen(new PhoneStateListener(){
#Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
System.out.println("incomingNumber : "+incomingNumber);
WindowManager windowManager = (WindowManager) context.getSystemService(WINDOW_SERVICE);
View view = LayoutInflater.from(context).inflate(R.layout.popup_window, null); // Code for inflating xml layout
int LAYOUT_FLAG;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY;
} else {
LAYOUT_FLAG = WindowManager.LayoutParams.TYPE_PHONE;
}
WindowManager.LayoutParams params = new WindowManager.LayoutParams(
WindowManager.LayoutParams.WRAP_CONTENT,
WindowManager.LayoutParams.WRAP_CONTENT,
LAYOUT_FLAG,
WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN,
PixelFormat.TRANSLUCENT);
windowManager.addView(view, params);
}
},PhoneStateListener.LISTEN_CALL_STATE);
}
}
add the below xml file on the folder
your project > android > app > src > main > res > layout > popup_window.xml
popup_window.xml
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="5dp"
android:background="#000000"
card_view:cardCornerRadius="4dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#drawable/popup_color"
android:orientation="vertical"
tools:ignore="UselessParent">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<ImageView
android:id="#+id/paymentlogo"
android:layout_width="65dp"
android:layout_height="65dp"
android:scaleType="fitCenter"
android:src="#drawable/rsoft_logo"
app:srcCompat="#drawable/rsoft_logo" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal">
<TextView
android:id="#+id/lbl_name"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_marginLeft="6dp"
android:layout_weight="0.3"
android:singleLine="true"
android:text="Anand"
android:textColor="#000000"
android:textSize="20sp" />
<ImageView
android:id="#+id/iv_close"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1.7"
android:src="#drawable/ic_close_black" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<TextView
android:id="#+id/txt_record_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="TextView"
android:visibility="gone"
tools:ignore="HardcodedText" />
<View
android:id="#+id/btw_view"
android:layout_width="fill_parent"
android:layout_height="1dp"
android:layout_gravity="center"
android:background="#bab9b9" />
<LinearLayout
android:id="#+id/details_adp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal"
android:padding="5dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:padding="3dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<LinearLayout
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tv_icon"
android:layout_width="17dp"
android:layout_marginTop="4dp"
android:layout_height="17dp"
android:layout_weight="1"
android:textColor="#000000"
android:src="#android:drawable/sym_call_incoming"
android:textSize="10sp" />
<TextView
android:id="#+id/tv_mobile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_weight="1"
android:text="7667673691"
android:padding="0dp"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
<TextView
android:id="#+id/tv_mobile_"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:layout_marginTop="4dp"
android:text="Incomingg"
android:textColor="#000000"
android:textSize="12sp" />
<!-- <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="4dp"
android:padding="3dp">
<ImageView
android:id="#+id/iv_im"
android:layout_width="14dp"
android:layout_height="14dp"
android:src="#drawable/sim" />
<TextView
android:id="#+id/tv_sim"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Incomingg"
android:textColor="#000000"
android:textSize="12sp" />
</LinearLayout>-->
</LinearLayout>
<TextView
android:id="#+id/tv_lead"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="4dp"
android:text="Save As Lead"
android:background="#drawable/rounded_btn"
android:padding="8dp"
android:layout_marginTop="6dp"
android:textColor="#000000"
android:textSize="16sp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
You can use flutter_overlay_window. Its JAVA only but works fine. The example app has a truecaller like overlay demo. The other answer is correct, no it can't be done in pure flutter.

Not displaying OK button in cardview in pop up dialog [duplicate]

This question already has answers here:
Add positive button to Dialog
(3 answers)
Closed 5 years ago.
I am new in android app development. I am making a project in android-studio.I want to show pop up dialog whatever I have declared in xml file but OK button is not showing. If anyone knows about it, please share your answer.xml and java codes are below
image_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical">
<!--<ImageView android:layout_width="wrap_content"-->
<!--android:layout_height="wrap_content" android:src="YOUR IMAGE"/>-->
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardViewbluetooth"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:paddingTop="180dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Bluetooth not enabled"
android:textSize="20dp"
android:textStyle="bold"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Please enable bluetooth in settings and restart this application"
android:textStyle="bold"/>
<Button android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="OK" android:onClick="dismissListener"/>
</LinearLayout>
</android.support.v7.widget.CardView></LinearLayout>
activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<ScrollView
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:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
tools:context="litifer.awesome.game.litifer_carddemo.MainActivity"
>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageBeacon"
android:src="#drawable/beacon"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView1text"
android:text="Beacon Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageWifi"
android:src="#drawable/wifi"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView2text"
android:text="Wifi Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imageCustomerReview"
android:src="#drawable/customerreview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView3text"
android:text="CustomerReview Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagecardview"
android:src="#drawable/cardview"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView4text"
android:text="CardView Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5"
app:cardCornerRadius="5dp"
android:layout_gravity="center"
android:layout_marginTop="10dp"
app:cardElevation="0dp"
android:clickable="true"
app:cardBackgroundColor="#android:color/transparent"
android:background="#33FF0000"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/imagedemo"
android:src="#drawable/demo"
android:adjustViewBounds="true"
android:layout_gravity="center"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/cardView5text"
android:text="Test All Demo"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:textSize="20dp"
android:textStyle="bold"
android:layout_marginRight="20dp"
android:layout_marginBottom="10dp"
/>
</LinearLayout>
</android.support.v7.widget.CardView>
</LinearLayout> </ScrollView>
MainActivity.java
public class MainActivity extends AppCompatActivity {
private ImageView beacon,cardview,customerreview,demo,wifi;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
beacon = (ImageView)findViewById(R.id.imageBeacon);
beacon.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
if (mBluetoothAdapter == null) {
// Device does not support Bluetooth
} else {
if (!mBluetoothAdapter.isEnabled()) {
// Bluetooth is not enable :)
Dialog settingsDialog = new Dialog(MainActivity.this);
settingsDialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(getLayoutInflater().inflate(R.layout.image_layout
, null));
settingsDialog.show();
}
}
}
});
}
}
try this
Dialog settingsDialog = new Dialog(this);
settingsDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
settingsDialog.setContentView(R.layout.image_layout);
settingsDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
settingsDialog.setCancelable(true);
settingsDialog.setTitle("Title...");
settingsDialog.show();

Android Tabhost within Tabhost Not Working (XML issue I think)

I have done this before, but for the life of me I cant remember.
I'm wanting a tab with in a tab. This is my mainactivity
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TabHost tabHost = getTabHost();
TabHost.TabSpec Login = tabHost.newTabSpec("Login");
// setting Title and Icon for the Tab
Login.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab1));
Intent LoginIntent = new Intent(this, Tab1Activity.class);
LoginIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Login.setContent(LoginIntent);
// Tab for jobs
TabHost.TabSpec Jobs = tabHost.newTabSpec("Jobs");
Jobs.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab2));
Intent JobsIntent = new Intent(this, Tab2Activity.class);
JobsIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs.setContent(JobsIntent);
TabHost.TabSpec Jobs3 = tabHost.newTabSpec("Jobs3");
Jobs3.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent JobsIntent3 = new Intent(this, Tab3Activity.class);
JobsIntent3.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Jobs3.setContent(JobsIntent3);
// Adding all TabSpec to TabHost
tabHost.addTab(Login);
tabHost.addTab(Jobs);
tabHost.addTab(Jobs3);
}
This is Tab2Activity.java
public class Tab2Activity extends TabActivity
{
#Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.tab2);
/////////////////////////
TabHost tabHost2 = getTabHost();
TabHost.TabSpec Gmapped = tabHost2.newTabSpec("InnerTabs");
// setting Title and Icon for the Tab
Gmapped.setIndicator("", getApplicationContext().getResources().getDrawable(R.drawable.tab3));
Intent GmappedIntent = new Intent(this, Tab3Activity.class);
GmappedIntent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
Gmapped.setContent(GmappedIntent);
tabHost2.addTab(Gmapped);
}
and Tab2.xml
<ScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center"
android:background="#332b2b"
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">
<LinearLayout
android:id="#+id/linearlayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<Button
android:id="#+id/veganfestival"
android:text="Aberdeen"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
<TextView
android:id="#+id/blank"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/venue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Venue"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/address"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Address"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/city"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="City"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/postcode"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Postcode"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/Vdate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Date"
android:textSize="20dp"
android:textColor="#ffffff" />
<TextView
android:id="#+id/Vtime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="20dp"
android:textColor="#ffffff" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#6f844a" />
<TextView
android:id="#+id/blankagain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="20dp"
android:textColor="#ffffff" />
<Button
android:id="#+id/nav"
android:text="Take Me There"
android:textColor="#FFFFFF"
android:textSize="30sp"
android:layout_width="match_parent"
android:layout_height="60dp"
android:background="#drawable/buttonshape"
android:shadowColor="#A8A8A8"
android:shadowDx="0"
android:shadowDy="0"
android:shadowRadius="5"
/>
</LinearLayout>
</ScrollView>
I have not been developing long, but I understand I need to at TabHost to Tab2.xml, but unsure were. Could someone help out.
If you want an advice, use TabLayout instead, is more easy:
TabLayout Example

Android Layout - Adding Dynamic Textview and EditText

In one of my project I want to create a layout like given Image
In image assume that Red boxes are Textviews and Blue boxes are EditText
The number of rows is not known. It depends on web service Response. How can I achieve this.
You can try like this codes. Such as
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3" >
<TextView
android:id="#+id/textView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="First Row" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="3"
android:orientation="horizontal" >
<Button
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Ok" />
<Button
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I expect it will be helpful for you. Best of luck!
Try adding views dynamically in linear layout which is inside scroll view.
Try this code.I know it is not exact solution.But,Hope it gives you some idea.
public class MainActivity extends Activity {
ScrollView scrollview;
LinearLayout linearLayout;
LinearLayout.LayoutParams layoutParams;
static int i;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
scrollview = (ScrollView)findViewById(R.id.scrollview);
linearLayout = (LinearLayout)findViewById(R.id.linearlayout);
Button button = (Button)findViewById(R.id.button);
layoutParams = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
button.setOnClickListener(new OnClickListener(){
public void onClick(View v) {
TextView view = new TextView(MainActivity.this);
view.setText(++i+" view");
linearLayout.addView(view, layoutParams);
}
});
}}
first inf_child.xml layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/inf_dynamicLl"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/btnContainer"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
android:text="OK"/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
android:text="Cancel"/>
</LinearLayout>
</LinearLayout>
second inf_dynamic_view.xml layout which will generate row dynamically:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/inner_linear_layout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
>
<TextView
android:id="#+id/firstText"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/secontText"
android:layout_width="0dp"
android:layout_weight="0.25"
android:layout_height="wrap_content"
/>
<TextView
android:id="#+id/ThirdText"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.25" />
<EditText
android:id="#+id/editText"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="0.25"
/>
</LinearLayout>
if (convertView == null) {
LayoutInflater infalInflater = (LayoutInflater) mContext.getSystemService(mContext.LAYOUT_INFLATER_SERVICE);
convertView = infalInflater.inflate(R.layout.inf_child, null);
}
LinearLayout dynamicLl = (LinearLayout) convertView.findViewById(R.id.inf_dynamicLl);
for (int rowCounter = 0; rowCounter < parentData.get(groupPosition).childData.get(childPosition).price.size(); rowCounter++)
createRow(dynamicLl, parentData.get(groupPosition).childData.get(childPosition).price.get(rowCounter), groupPosition);
=> create row dynamically
private void createRow(LinearLayout lView, String price, int childPosition) {
LayoutInflater vi = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View l = vi.inflate(R.layout.inf_dynamic_view, null);
final TextView tvFirst, tvSecond,tvThird;
final EditText edt1;
lView.addView(l);
lView.refreshDrawableState();
}

A simple TabHost in android

I have created a simple tab project in Android
MainActivity.java
public class MainActivity extends TabActivity {
// TabSpec Names
private static final String TAB1 = "Tab1";
private static final String TAB2 = "Tab2";
private static final String TAB3 = "Tab3";
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Inbox Tab
TabSpec inboxSpec = tabHost.newTabSpec(TAB1);
Intent inboxIntent = new Intent(this, Tab1.class);
inboxSpec.setIndicator(TAB1);
// Tab Content
inboxSpec.setContent(inboxIntent);
// Outbox Tab
TabSpec PriceSpec = tabHost.newTabSpec(TAB2);
Intent PriceIntent = new Intent(this, Tab2.class);
PriceSpec .setIndicator(TAB2);
PriceSpec.setContent(PriceIntent);
// Profile Tab
TabSpec DistanceSpec = tabHost.newTabSpec(TAB3);
Intent DistanceIntent = new Intent(this, Tab3.class);
DistanceSpec .setIndicator(TAB3);
DistanceSpec.setContent(DistanceIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(inboxSpec);
tabHost.addTab(PriceSpec);
tabHost.addTab(DistanceSpec);
//Set the current value tab to default first tab
tabHost.setCurrentTab(0);
//Setting custom height for the tabs
final int height = 45;
tabHost.getTabWidget().getChildAt(0).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(1).getLayoutParams().height = height;
tabHost.getTabWidget().getChildAt(2).getLayoutParams().height = height;
}
}
main.xml
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
OUTPUT ::
How can i make a horizontal set of 5 buttons on top of the tab to get something like this in the below figure
What are the code changes i need to make in main.xml ?
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<include layout="#layout/screen_topbar" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1" >
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#color/white" >
</TabWidget>
</FrameLayout>
</LinearLayout>
</TabHost>
And TopBar layout-
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/buttonlayout"
android:layout_width="fill_parent"
android:layout_height="53dp"
android:gravity="top"
android:orientation="horizontal" >
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
Just try this sure it will work..
Add one more LinearLayout define your buttons inside above TabWidget and fixed your FrameLayout height with weight, look below code:
<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="0" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
</LinearLayout>
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#drawable/dm_footer_bg"
android:orientation="horizontal" />
<FrameLayout
android:id="#+android:id/realtabcontent"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
</TabHost>
try this. Replace your main.xml code with the below code. it will work
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:orientation="horizontal">
<Button android:layout_width="100dp" android:text=" Button 1"
android:layout_height="wrap_content" />
<Button android:layout_width="100dp" android:text=" Button 2"
android:layout_height="wrap_content" />
<Button android:layout_width="100dp" android:text=" Button 3"
android:layout_height="wrap_content" />
<Button android:layout_width="100dp" android:text=" Button 4"
android:layout_height="wrap_content" />
</LinearLayout>
<TabHost
android:id="#android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<LinearLayout
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TabWidget
android:id="#android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="#android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
</LinearLayout>
</TabHost>
</LinearLayout>

Categories

Resources