It is showing cannot resovle R.
how i can solve this problem?????
if you need xml file to solve problem ,ask me in comment
Please help
..................................................................................................................................................................................................................................................................................................................
Here's the java code:
package com.example.android.justjava;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
import java.text.NumberFormat;
/**
* This app displays an order form to order coffee.
*/
public class MainActivity extends AppCompatActivity {
int quantity = 0;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
/**
* This method is called when the order button is clicked.
*/
public void submitOrder(View view) {
int price= quantity*16;
String priceMessage="total:" + (quantity*16) ;
priceMessage=priceMessage +"\nThank You!";
displayMessage(priceMessage);
}
/**
* This method displays the given text on the screen.
*/
private void displayMessage(String message) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(message);
}
public void increase(View view) {
quantity = quantity + 1;
displayPrice(quantity*16);
display(quantity);
}
public void decrease(View view) {
quantity = quantity - 1;
displayPrice(quantity*16);
display(quantity);
}
/**
* This method displays the given quantity value on the screen.
*/
private void display(int number) {
TextView quantityTextView = (TextView) findViewById(R.id.quantity_text_view);
quantityTextView.setText("" + number);
}
/**
* This method displays the given price on the screen.
*/
private void displayPrice(int number) {
TextView priceTextView = (TextView) findViewById(R.id.price_text_view);
priceTextView.setText(NumberFormat.getCurrencyInstance().format(number);
}
here's the xml file:::
................................................................................................................................................................................................................................................
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/w"
android:orientation="vertical"
>
<TextView
android:id="#+id/txt1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginTop="20dp"
android:text="Welcome to Ordering Menu"
android:textColor="#android:color/white"
android:textSize="25sp"
app:fontFamily="#font/crafty_girls" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_marginTop="20dp"
android:layout_height="wrap_content"
android:orientation="horizontal">
<ImageView
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_marginLeft="20dp"
android:src="#drawable/cappo"/>
<Button
android:id="#+id/btn2"
android:layout_width="48dp"
android:layout_height="48dp"
android:textSize="30sp"
android:layout_marginLeft="50dp"
android:layout_marginTop="20dp"
android:onClick="increase"
android:text="+"
android:textColor="#android:color/black"
android:background="#android:color/white" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:text="0"
android:textSize="20sp"
android:textColor="#android:color/white" />
<Button
android:id="#+id/btn3"
android:layout_width="50dp"
android:textColor="#android:color/black"
android:background="#android:color/white"
android:layout_height="50dp"
android:textBold="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="20dp"
android:onClick="decrease"
android:textSize="30sp"
android:text="-" />
</LinearLayout>
<TextView
android:id="#+id/kk"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="170dp"
android:text="Price" />
<TextView
android:id="#+id/price_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:text="$0"
android:textColor="#000000" />
<Button
android:id="#+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="15dp"
android:onClick="submitOrder"
android:text="ORDER" />
</LinearLayout>
</android.support.constraint.ConstraintLayout>
This may not be the case for you but worth a shot, sometimes Android studio is glitchy and needs to be closed/ reopened. Also you could try, Build > Clean Project.
Try from android studio menu File -> Invalidate Caches and Restart -> Invalidate and Restart
i'm new in this type of developing ,so can i know where can i find this import list
So i can suggest you to check few things.
Make sure you have installed your targeted build tools. Eg: API 28
Check the package name in your AndroidManifest.xml file. You may have deleted the package name from the manifest file mistakenly.
If none of the above in your case, try to import com.example.android.justjava.R
Related
So i've make some change's in my app (it was about nesting layouts - My root layout, was linear layout,i wanted to change it to relative layout,i remember,it was something wrong with lines like xlmns:tools etc. I've copy those lines from my previous app,but then i've got an error that something is missing,so i google it,and somebody wrote about delete .idea and .gradle folders so i did,and now,my avd showing me "old content" just app before some changes. How i can solve it? The application that i've trying to make,it's just an typical clicker at case of my course. It's about to counting score of two teams. Screen with an issue https://imgur.com/a/U9gianT
<?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:layout_height="match_parent"
android:layout_width="match_parent">
<Button
android:layout_gravity="center"
android:id="#+id/reset_score"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/resetBTN"
android:layout_marginTop="15dp"
android:onClick="reset_score"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="32dp"
/>
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<TextView
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_a"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"
android:layout_marginTop="16dp"/>
<TextView
android:layout_gravity="center"
android:id="#+id/team_a_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_a_points"
android:layout_marginTop="16dp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"
android:textSize="56sp"/>
<Button
android:layout_gravity="center"
android:id="#+id/three_points_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_points_btn"
android:layout_marginTop="24dp"
android:onClick="addThreePointsA"/>
<Button
android:layout_gravity="center"
android:id="#+id/two_points_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_points_btn"
android:layout_marginTop="24dp"
android:onClick="addTwoPointsA"/>
<Button
android:layout_gravity="center"
android:id="#+id/free_throw_a"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/free_throw_btn"
android:layout_marginTop="24dp"
android:onClick="addOnePointA"/>
</LinearLayout>
<View
android:layout_width="1dp"
android:layout_height="340dp"
android:background="#android:color/darker_gray"
android:layout_marginTop="15dp"/>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical"
>
<TextView
android:layout_marginTop="16dp"
android:layout_gravity="center"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_b"
android:textSize="14sp"
android:textColor="#616161"
android:fontFamily="sans-serif-medium"/>
<TextView
android:layout_gravity="center"
android:id="#+id/team_b_points"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/team_b_score"
android:layout_marginTop="16dp"
android:textSize="56sp"
android:textColor="#000000"
android:fontFamily="sans-serif-light"/>
<Button
android:layout_gravity="center"
android:id="#+id/three_points_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_3_points_btn"
android:layout_marginTop="24dp"
android:onClick="addThreePointsB"/>
<Button
android:layout_gravity="center"
android:id="#+id/two_points_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/_2_points_btn"
android:layout_marginTop="24dp"
android:onClick="addTwoPointsB"/>
<Button
android:layout_gravity="center"
android:id="#+id/free_throw_b"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/free_throw_btn"
android:layout_marginTop="24dp"
android:onClick="addOnePointB"/>
</LinearLayout>
package com.example.kacper.courtcounter;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int team_a_score = 0;
int team_b_score = 0;
private void display_a_score(int score){
TextView scoreView = (TextView) findViewById(R.id.team_a_points);
scoreView.setText(String.valueOf(score));
}
private void display_b_score(int score){
TextView scoreView = (TextView) findViewById(R.id.team_b_points);
scoreView.setText(String.valueOf(score));
}
public void addThreePointsA(View view) {
team_a_score = team_a_score+3;
display_a_score(team_a_score);
}
public void addTwoPointsA(View view) {
team_a_score = team_a_score+2;
display_a_score(team_a_score);
}
public void addOnePointA(View view) {
team_a_score = team_a_score+1;
display_a_score(team_a_score);
}
public void addThreePointsB(View view) {
team_b_score = team_b_score+3;
display_b_score(team_b_score);
}
public void addTwoPointsB(View view) {
team_b_score = team_b_score+2;
display_b_score(team_b_score);
}
public void addOnePointB(View view) {
team_b_score = team_b_score+1;
display_b_score(team_b_score);
}
public void reset_score(View view) {
team_a_score = 0;
team_b_score = 0;
display_a_score(team_a_score);
display_b_score(team_b_score);
}
}
Just Clean and rebuild your project and then uninstall app from device and then run again in device it will works fine (If you really make changes in code)
I am creating a diet app for myself and I do not know how to transfer result from one calculation which was done in a different activity and use it in another one.
To make things more complicated, I want my spinner in MoreLooseWeightDetails.class to have a list of different diet types which have different fat, proteins and carb ratio. Every time the user choose different type it should automatically change the ratio.
This is where the calculation is being done and has to be trnasfered to MoreLooseWeightDetails.class
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Spinner;
import android.widget.TextView;
public class LooseWeight extends AppCompatActivity {
TextView TotalCal;
EditText numb2;
Spinner ActLvl;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_loose_weight);
numb2 = (EditText) findViewById(R.id.value1);
ActLvl = (Spinner) findViewById(R.id.value2);
TotalCal = (TextView)findViewById(R.id.resultDisplay);
final Spinner ActLvl = (Spinner)findViewById(R.id.value2);
ArrayAdapter<String> myAdapter = new ArrayAdapter<>(LooseWeight.this, android.R.layout.simple_expandable_list_item_1,getResources().getStringArray(R.array.lvl));
myAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
ActLvl.setAdapter(myAdapter);
Button calcBtn = (Button)findViewById(R.id.result);
calcBtn.setOnClickListener(new View.OnClickListener(){
#Override
public void onClick (View view) {
float numb3 = Float.parseFloat(numb2.getText().toString());
float a = numb3 * 24;
float b = a * Float.parseFloat(ActLvl.getSelectedItem().toString());
float c = b - 500;
TotalCal.setText(Float.toString(c));
}
});
Button extra = (Button)findViewById(R.id.advance);
extra.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View arg0) {
Intent intent = new Intent(getApplicationContext(),MoreLooseWeightDetails.class);
startActivity(intent);
}
});
}
}
Here is the MoreLooseWeightDetails.class
package com.fitup.fit_up;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
public class MoreLooseWeightDetails extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_more_loose_weight_details);
}
}
Here is the MoreLooseWeightDetails.xml
<?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:id="#+id/activity_more_loose_weight_details"
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.fitup.fit_up.MoreLooseWeightDetails">
<TextView
android:text="TextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:id="#+id/Title3"
tools:text="More"
android:textSize="36sp" />
<TextView
android:text="Select Type of Diet"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/Title3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="19dp"
android:id="#+id/Info3"
android:textSize="30sp" />
<Spinner
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/Info3"
android:layout_centerHorizontal="true"
android:layout_marginTop="13dp"
android:id="#+id/spinner" />
<TextView
android:text="You Should Eat :"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:id="#+id/Info4"
android:textSize="30sp"
android:layout_below="#+id/spinner"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text="Protein (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit1"
android:textSize="24sp"
android:layout_below="#+id/Info4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_marginTop="78dp" />
<TextView
android:text="Fat (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/unit3"
android:textSize="24sp"
android:layout_centerVertical="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit3"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/result1"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignLeft="#+id/result2"
android:layout_alignStart="#+id/result2" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/unit2"
android:id="#+id/result2"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignLeft="#+id/result3"
android:layout_alignStart="#+id/result3" />
<TextView
android:text=""
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/unit2"
android:id="#+id/result3"
android:textSize="30sp"
android:textAlignment="center"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_toRightOf="#+id/unit2"
android:layout_toEndOf="#+id/unit2" />
<TextView
android:text="Carbohydrates (grams):"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="43dp"
android:id="#+id/unit2"
android:textSize="24sp"
android:layout_below="#+id/unit1"
android:layout_alignRight="#+id/unit1"
android:layout_alignEnd="#+id/unit1" />
</RelativeLayout>
So, when I press the Increment or Decrement button on my device, the app force closes. I tried using debugger but can't seem to figure out the problem. It is basically a single screen app that shows Order summary.
Here is the XML Code:
<ScrollView 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"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:paddingBottom="#dimen/activity_vertical_margin"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin">
<TextView
android:id="#+id/name_field"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="QUANTITY!" />
<CheckBox
android:id="#+id/whipped_cream_checkbox"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="24dp"
android:text="Whipped Cream"
android:textSize="16sp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="decrement"
android:text="-" />
<TextView
android:id="#+id/quantity_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:text="0"
android:textColor="#android:color/black"
android:textSize="16sp" />
<Button
android:layout_width="48dp"
android:layout_height="48dp"
android:onClick="increment"
android:text="+" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="submitOrder"
android:text="Order" />
<TextView
android:id="#+id/order_summary"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="16dp"/>
</LinearLayout>
</ScrollView>
The JAVA code:
package com.example.android.timeforacoffee;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
int quantity=0;
String priceMessage="Name: Moksh \n" + "Your total is ₹" +quantity;
public void displayQuanity(int quantity) {
TextView quantity_value=(TextView) findViewById(R.id.quantity_text_view);
quantity_value.setText(quantity);
}
/**
*This method is called when the - button is pressed.
*/
public void decrement(View view) {
displayQuanity(quantity - 1);
}
/**
*
* This method is called when the + button is clicked.
*/
public void increment(View view) {
displayQuanity(quantity + 1);
}
public void displayMessage(String priceMessage) {
TextView order_summary=(TextView) findViewById(R.id.order_summary);
order_summary.setText(priceMessage);
}
/**
* This method is called when the Order button is clicked.
*/
public void submitOrder(View view) {
displayMessage(priceMessage);
}
}
I think the issue is in the below line of code
quantity_value.setText(quantity);
Note that when you pass any integer to setText function android considers the integer as an reference to a string reource and searches for that string in the reource file, if that string is not found your app will crash with android.content.res.Resources$NotFoundException.
You can simply fix this issue by explicitly parsing the integer as string as below
quantity_value.setText(String.valueOf(quantity));
My application is working successfully in Android 2.x to 4.1.x
In Google TV emulator i am running my existing application.
Google TV is not support touch input, So user must use navigation flow like move left, move right, move top and move bottom.
But this control can not point on ImageButton control.
How can reach my pointer for operate ImageButton.?
XML Layout :
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/mainLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<TextView
android:id="#+id/headingTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="20dip"
android:gravity="center_horizontal"
android:text="Kit - Device Registration"
android:textSize="75sp" />
<RelativeLayout
android:id="#+id/kitDetailsRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/headingTextView"
android:layout_centerInParent="true"
android:layout_marginTop="100dp" >
<TextView
android:id="#+id/WebURLTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_marginTop="30dp"
android:gravity="right"
android:text="Web Url:"
android:textSize="50dp" />
<EditText
android:id="#+id/WebURLEditText"
style="#style/EditTextStyle"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_marginLeft="60dp"
android:layout_marginTop="30dp"
android:layout_toRightOf="#id/WebURLTextView"
android:hint="Enter Web Url"
android:text=""
android:textSize="40dp" />
<TextView
android:id="#+id/KitNoTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/WebURLTextView"
android:layout_below="#id/WebURLEditText"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="KIT No:"
android:textSize="50dp" />
<EditText
android:id="#+id/KitNoEditText"
style="#style/EditTextStyle"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_below="#id/WebURLTextView"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/KitNoTextView"
android:hint="Enter KIT No"
android:textSize="40dp" />
<TextView
android:id="#+id/UniqueIdTextView"
android:layout_width="250dp"
android:layout_height="wrap_content"
android:layout_alignLeft="#id/WebURLTextView"
android:layout_below="#id/KitNoEditText"
android:layout_marginTop="5dp"
android:gravity="right"
android:text="Unique Id:"
android:textSize="50dp" />
<EditText
android:id="#+id/UniqueIdEditText"
android:layout_width="700dp"
android:layout_height="wrap_content"
android:layout_below="#id/KitNoTextView"
android:layout_marginLeft="60dp"
android:layout_marginTop="10dp"
android:layout_toRightOf="#id/UniqueIdTextView"
android:editable="false"
android:focusable="false"
android:textSize="40dp" />
<Button
android:id="#+id/ih_comBtn"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_above="#+id/KitNoTextView"
android:layout_toRightOf="#+id/WebURLEditText"
android:text="#string/lbl_host_name"
android:textSize="35sp" />
</RelativeLayout>
<ImageView
android:id="#+id/topSettingsIcon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dip"
android:layout_marginTop="10dip"
android:background="#drawable/streak_settings" />
<RelativeLayout
android:id="#+id/kitControlRelativeLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="10dp" >
<ImageButton
android:id="#+id/quitBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:background="#drawable/quit_button" />
<ImageButton
android:id="#+id/verifyBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/quitBtn"
android:layout_marginRight="20dip"
android:layout_toLeftOf="#id/quitBtn"
android:background="#drawable/register_button" />
<ImageButton
android:id="#+id/clearBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#id/quitBtn"
android:layout_marginLeft="20dip"
android:layout_toRightOf="#id/quitBtn"
android:background="#drawable/clear_button" />
</RelativeLayout>
</RelativeLayout>
Java File Code :
import android.os.Bundle;
//Other Imports
public class <classs Name> extends Activity {
EditText webUrlEditTextObj;
EditText uniqueIdEditTextObj;
/**
* Refers to Register image button
*/
private ImageButton registerBtnObj;
/**
* Refers to Quit image button
*/
private ImageButton quitBtnObj;
/**
* Refers to Clear image button
*/
private ImageButton clearBtnObj;
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setContentView(R.layout.<XML file Name>);
//...
registerBtnObj = (ImageButton) findViewById(R.id.verifyBtn);
quitBtnObj = (ImageButton) findViewById(R.id.quitBtn);
clearBtnObj = (ImageButton) findViewById(R.id.clearBtn);
verifyBtnObj.setOnClickListener(verifyListener);
quitBtnObj.setOnClickListener(quitListener);
clearBtnObj.setOnClickListener(clearListener);
//...
}
/**
* Listener for Register button click.
*/
private OnClickListener verifyListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
/**
* Listener for Quit button click.
*/
private OnClickListener quitListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
/**
* Listener for Clear button click.
*/
private OnClickListener clearListener = new OnClickListener() {
public void onClick(View v) {
/**
* Block of code
*/
}
};
}
Make sure your ImageButtons are marked as focusable. You'll also want to make sure you set the nextFocus* related attributes as well. The following is from my project, Serenity for Android which uses ImageButtons on the OSD when playing a video.
<ImageButton
android:id="#+id/osd_rewind_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:focusable="true"
android:nextFocusRight="#+id/mediacontroller_play_pause"
android:nextFocusUp="#+id/mediacontroller_seekbar"
android:scaleType="fitXY"
style="#android:style/MediaButton.Rew"
android:src="#drawable/skipback_selector"
tools:ignore="ContentDescription" />
Again make sure you set the android:focusable to true. All source code for my app is available to look at as well.
https://github.com/NineWorlds/serenity-android/blob/master/serenity-app/res/layout-large/serenity_media_controller.xml
How to make this kind of tab in Android [http://i.stack.imgur.com/rIbUX.png]
just mention that see the overlap area, when you click on of the tab, the overlap changed.
here is one chinese version example in which I think that's what I want to have, but they don't provide the complete code, and I have no idea how to go on this project.
http://www.oschina.net/question/54100_29061
I am currently using Android 3.2 and ICS 4+ to implement this project, so welcome if that's possible to implement competible with Framgment.
I finally I made the solution by myself. I just leave the native tab host implementation, make up my own.
here is the screen shot:
[http://i.stack.imgur.com/1mXLZ.png]
here is the Activity code:
import android.app.Activity;
import android.graphics.drawable.Drawable;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.ImageView;
import android.widget.TextView;
public class PelesysTabHostActivity extends Activity {
private ImageView ib1, ib2, ib3, last;
private Drawable pressed, released;
private TextView tv,tv1,tv2,tv3;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
ib1 = (ImageView) this.findViewById(R.id.imageView1);
ib2 = (ImageView) this.findViewById(R.id.imageView2);
ib3 = (ImageView) this.findViewById(R.id.imageView3);
tv = (TextView) this.findViewById(R.id.textView1);
tv1= (TextView) this.findViewById(R.id.textView11);
tv2= (TextView) this.findViewById(R.id.textView22);
tv3= (TextView) this.findViewById(R.id.textView33);
pressed = getResources().getDrawable(R.drawable.ui_table_tab_button);
released = getResources().getDrawable(
R.drawable.ui_table_tab_button_disabled);
ib1.setImageDrawable(pressed);
last = ib1;
ib1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib1.setImageDrawable(pressed);
last = ib1;
tv.setText("I am super 1");
ib1.bringToFront();
tv1.bringToFront();
}
});
ib2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib2.setImageDrawable(pressed);
last = ib2;
tv.setText("TWO!!! I am super 2");
ib2.bringToFront();
tv2.bringToFront();
}
});
ib3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
last.setImageDrawable(released);
ib3.setImageDrawable(pressed);
last = ib3;
tv.setText(" III !!! I am super 3");
ib3.bringToFront();
tv3.bringToFront();
}
});
}
}
here is the layout file I used (main.xml)
<?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" >
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="fill_parent"
android:layout_height="330dp"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" >
<ImageView
android:id="#+id/imageView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ui_table_bg_coursedetail" />
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:text="Large Text"
android:textAppearance="?android:attr/textAppearanceLarge"
android:textColor="#000000" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/relativeLayout2"
android:layout_alignParentLeft="true"
android:layout_marginLeft="326dp" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="90dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<ImageView
android:id="#+id/imageView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="180dp"
android:src="#drawable/ui_table_tab_button_disabled" />
<TextView
android:id="#+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView1"
android:layout_marginLeft="50dp"
android:text="1"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView2"
android:layout_marginLeft="50dp"
android:text="2"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
<TextView
android:id="#+id/textView33"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/imageView3"
android:layout_marginLeft="50dp"
android:text="3"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" />
</RelativeLayout>
Just a week now I used this : https://github.com/AdilSoomro/Iphone-Tab-in-Android
Very well worked! You can customize it as its in your first picture