I have problem with drawerLayout. in drawerLayout, i have two Linearlayouts. one is the main menu that shows directly, the otherone is active with drawer slide. when i slide the drawer menü i cant click the buttons. but when i remove the second linearLayout then the buttons in the drawer work. how can i solve it?
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=""
android:clickable="true"
android:contextClickable="true">
<LinearLayout
android:orientation="vertical"
android:layout_gravity="left|start"
android:background="#color/list_back"
android:layout_width="250dp"
android:layout_height="match_parent"
android:onClick="setContentView"
android:contextClickable="true"
android:clickable="true">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Ana Sayfa"
android:id="#+id/buttonAnaSayfa"
android:onClick="setContentView"
android:clickable="false"
android:contextClickable="false"
android:nestedScrollingEnabled="false" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Kalori Tablosu"
android:id="#+id/buttonKalori"
android:onClick="setContentView"
android:clickable="true"
android:contextClickable="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Glisemik İndeks Tablosu"
android:id="#+id/buttonGITablosu"
android:onClick="setContentView"
android:clickable="true"
android:contextClickable="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Vücut Kütle İndeksi"
android:id="#+id/buttonVucutKutle"
android:onClick="setContentView"
android:clickable="true"
android:contextClickable="true" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="center">
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonKaloriListesi"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/kalori_listesi_button"
android:background="#null"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonGITablosu"
android:src="#drawable/gi_tablosu_button"
android:layout_below="#+id/imageButtonKaloriListesi"
android:layout_alignParentStart="true"
android:background="#null"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonBugunKaloriHesabi"
android:src="#drawable/bugun_kac_kalori_aldin_button"
android:background="#null"
android:layout_above="#+id/imageButtonVucutKutleIndeks"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonVucutKutleIndeks"
android:src="#drawable/vucut_kutle_indeksi_button"
android:background="#null"
android:layout_centerVertical="true"
android:layout_alignStart="#+id/imageButtonBugunKaloriHesabi"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<Button
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="test"
android:id="#+id/buttontest1"
android:layout_gravity="center_horizontal" />
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_gravity="center_horizontal"
android:id="#+id/ad"
android:layout_marginTop="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"></LinearLayout>
</LinearLayout>
here is my .java ;
package com.azelirbrevo.glisemikindeks
public class "" extends AppCompatActivity {
//DrawerLayout drawerLayout;
//ActionBarDrawerToggle toggle;
//CharSequence actionBarTitle, appTitle;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.firstaftersplash);
ImageButton ImageButtonKaloriListesi = (ImageButton) findViewById(R.id.imageButtonKaloriListesi);
ImageButton imageButtonGITablosu = (ImageButton) findViewById(R.id.imageButtonGITablosu);
ImageButton imageButtonVucutKutleIndeks = (ImageButton) findViewById(R.id.imageButtonVucutKutleIndeks);
ImageButton imageButtonBugunKaloriHesabi = (ImageButton) findViewById(R.id.imageButtonBugunKaloriHesabi);
ImageButtonKaloriListesi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(firstAfterSplash.this, KaloriListesi.class);
startActivity(intent);
}
});
imageButtonGITablosu.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(firstAfterSplash.this, GITablosu.class);
startActivity(intent);
}
});
imageButtonVucutKutleIndeks.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(firstAfterSplash.this, VucutKutleIndexHesaplama.class);
startActivity(intent);
}
});
imageButtonBugunKaloriHesabi.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(firstAfterSplash.this, bugunKacKaloriAldim.class);
startActivity(intent);
}
});
//drawerLayout = (DrawerLayout) findViewById(R.id.drawerLayout);
//actionBarTitle = appTitle = getSupportActionBar().getTitle();
Button buttonAnasayfa = (Button) findViewById(R.id.buttonAnaSayfa);
Button buttonKalori = (Button) findViewById(R.id.buttonKalori);
Button buttonGı = (Button) findViewById(R.id.buttonGITablosu);
Button buttonVucutKutle = (Button) findViewById(R.id.buttonVucutKutle);
Button test = (Button) findViewById(R.id.buttontest1);
test.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Intent intent = new Intent(firstAfterSplash.this, TEST.class);
startActivity(intent);
}
});
buttonAnasayfa.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "tiklandi", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(firstAfterSplash.this, GITablosu.class);
startActivity(intent);
}
});
buttonKalori.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "tiklandi", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(firstAfterSplash.this, GITablosu.class);
startActivity(intent);
}
});
buttonGı.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "tiklandi", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(firstAfterSplash.this, GITablosu.class);
startActivity(intent);
}
});
buttonVucutKutle.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
Toast.makeText(getApplicationContext(), "tiklandi", Toast.LENGTH_SHORT).show();
Intent intent = new Intent(firstAfterSplash.this, GITablosu.class);
startActivity(intent);
}
});
}}
this is the design
You can create a application with Navigation drawer Activity here you can see custom layout inside drawer layout and inside layout you can set any type of widgets as button, TextView and any type what ever you want.
In xml file, my drawer menu items (LinearLayout and Buttons) were over my main LinearLayout. I just cut-paste it under the main LinearLayout and it helped.
here is the updated xml file of my project, hope will help someone.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/drawerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=""
android:clickable="true"
android:contextClickable="true">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:foregroundGravity="center">
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonKaloriListesi"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/kalori_listesi_button"
android:background="#null"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonGITablosu"
android:src="#drawable/gi_tablosu_button"
android:layout_below="#+id/imageButtonKaloriListesi"
android:layout_alignParentStart="true"
android:background="#null"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonBugunKaloriHesabi"
android:src="#drawable/bugun_kac_kalori_aldin_button"
android:background="#null"
android:layout_above="#+id/imageButtonVucutKutleIndeks"
android:layout_centerHorizontal="true"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<ImageButton
android:layout_width="360dp"
android:layout_height="wrap_content"
android:id="#+id/imageButtonVucutKutleIndeks"
android:src="#drawable/vucut_kutle_indeksi_button"
android:background="#null"
android:layout_centerVertical="true"
android:layout_alignStart="#+id/imageButtonBugunKaloriHesabi"
android:layout_marginTop="10dp"
android:foregroundGravity="center"
android:gravity="center"/>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="230dp"
android:layout_gravity="center_horizontal"
android:id="#+id/ad"
android:layout_marginTop="40dp"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"></LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_gravity="left|start"
android:layout_width="250dp"
android:layout_height="match_parent"
android:onClick="setContentView"
android:contextClickable="true"
android:clickable="true"
android:background="#85c7f1">
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/ButtonDrawerAnaSayfa"
android:background="#null"
android:layout_gravity="left"
android:gravity="left"/>
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/ButtonDrawerKalori"
android:background="#null"
android:layout_gravity="left"
android:gravity="left"/>
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/ButtonDrawerGI"
android:background="#null"
android:layout_gravity="left"
android:gravity="left"/>
<Button
android:layout_width="fill_parent"
android:layout_height="50dp"
android:id="#+id/ButtonDrawerVucutKutle"
android:background="#null"
android:layout_gravity="left"
android:gravity="left"/>
</LinearLayout>
Related
So basically I have attached my addimage.java code and mainpage.xml code below. whenever the user will click on addimage button he can select image and dynamically add images in my mainpage.xml file. So basically its like I want to transfer I image from activity to activity on a button click.
I tried doing that still I am stuck up a this specific point, where the user can selects image from gallery but still I don't know how will it get uploaded to mainpage.xml file.
Any help is highly appreciable.
this is my addimage.java code
public class addimage extends AppCompatActivity {
private ImageView imageView;
private Button addimage;
private ProgressBar progressBar;
android.content.Intent data;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addimage);
imageView = (ImageView) findViewById(R.id.imageView);
addimage = (Button) findViewById(R.id.addimage);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.INVISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, 1);
}
});
addimage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (imageView != null) {
/*uploadToFirebase(imageView);*/
} else {
Toast.makeText(getApplicationContext(), "PLEASE SELECT IMAGE", Toast.LENGTH_SHORT).show();
}
}
});
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
/* super.onActivityResult(requestCode, resultCode, data);*/
switch (requestCode) {
case 2://2 is from startActivityForResult(galleryIntent, 2);
try {
Uri selectedImage = data.getData(); //get photo uri
imageView.setImageURI(selectedImage);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
}
this is my mainpage.xml code
<?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:id="#+id/mainpage"
android:layout_height="match_parent"
tools:context=".mainpage">
<LinearLayout
android:orientation="vertical"
android:background="#color/Pink"
android:weightSum="10"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2">
<TextView
android:layout_width="950dp"
android:layout_height="550dp"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="5dp"
android:layout_marginBottom="0dp"
android:alpha="0.5"
android:background="#color/purple_200"
android:text=" BEGINNERS CALLIGRAPHY"
android:textAllCaps="false"
android:textColor="#color/DarkBlue"
android:textSize="25sp"
android:textStyle="bold" />
<Button
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="210dp"
android:layout_marginBottom="7dp"
android:text="PHOTOS"
android:textSize="20dp"
android:background="#color/white"
android:textColor="#color/purple_700"/>
<Button
android:id="#+id/button1"
android:layout_width="110dp"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentBottom="true"
android:layout_marginEnd="52dp"
android:layout_marginBottom="7dp"
android:text="VIDEOS"
android:textSize="20dp"
android:background="#color/white"
android:textColor="#color/purple_700"/>
</RelativeLayout>
<GridLayout
android:id="#+id/mainGrid"
android:layout_width="match_parent"
android:layout_height="949dp"
android:layout_weight="8"
android:alignmentMode="alignMargins"
android:columnCount="2"
android:columnOrderPreserved="false"
android:padding="14dp"
android:rowCount="3">
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp"
android:background="#color/Purple">
<LinearLayout
android:layout_width="149dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_image"
android:layout_width="150dp"
android:layout_height="180dp"
android:layout_row="0"
android:layout_column="0"
android:layout_gravity="center_horizontal"
android:src="#drawable/b1" />
</LinearLayout>
</androidx.cardview.widget.CardView/>
<!-- Row 2 -->
<!-- Column 1 -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="149dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_image2"
android:layout_width="150dp"
android:layout_height="180dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/b3" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Column 2 -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="149dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_image3"
android:layout_width="190dp"
android:layout_height="180dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/b4" />
</LinearLayout>
</androidx.cardview.widget.CardView>
<!-- Row 2 -->
<!-- Column 1 -->
<androidx.cardview.widget.CardView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_rowWeight="1"
android:layout_columnWeight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
android:layout_marginBottom="16dp"
app:cardCornerRadius="8dp"
app:cardElevation="8dp">
<LinearLayout
android:layout_width="149dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal|center_vertical"
android:layout_margin="16dp"
android:orientation="vertical">
<ImageView
android:id="#+id/imageview_image4"
android:layout_width="150dp"
android:layout_height="200dp"
android:layout_gravity="center_horizontal"
android:src="#drawable/b5" />
</LinearLayout>
</androidx.cardview.widget.CardView>
</GridLayout>
<ImageView
android:id="#+id/expanded_image"
android:layout_marginRight="30dp"
android:layout_width="350dp"
android:layout_height="900dp"
android:visibility="invisible"
android:layout_gravity="center"/>
<!--android:layout_gravity="center"-->
</LinearLayout>
</ScrollView>
If more code is required please comment below.
try to add code to this addimage class:
public class addimage extends AppCompatActivity {
private ImageView imageView;
private Button addimage;
private ProgressBar progressBar;
android.content.Intent data;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.addimage);
imageView = (ImageView) findViewById(R.id.imageView);
addimage = (Button) findViewById(R.id.addimage);
progressBar = (ProgressBar) findViewById(R.id.progressBar);
progressBar.setVisibility(View.INVISIBLE);
imageView.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
Intent galleryIntent = new Intent();
galleryIntent.setAction(Intent.ACTION_GET_CONTENT);
galleryIntent.setType("image/*");
startActivityForResult(galleryIntent, 1);
}
});
addimage.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View v) {
if (imageView != null) {
/*uploadToFirebase(imageView);*/
} else {
Toast.makeText(getApplicationContext(), "PLEASE SELECT IMAGE", Toast.LENGTH_SHORT).show();
}
}
});
}
#Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
switch (requestCode) {
case 1://1 is from startActivityForResult(galleryIntent, 2);
try {
Uri selectedImage = data.getData(); //get photo uri
imageView.setImageURI(selectedImage);
} catch (Exception e) {
e.printStackTrace();
}
break;
}
}
}
I designed two buttons b1,b2 inside "KeyboardService.java" which should update the value of PACK_LIB inside "Stickers.java".
Three files attached:
main_board_layout.xml
Stickers.java
KeyboardService.java
I assigned both buttons with IDs of Button1 = b1 and Button2 = b2.
The built is successful but when I click on the buttons both do not work.
I think it is maybe a problem with this line ->
final Button button1 = (Button) mainBoard.findViewById(R.id.b1);
Because the Buttons are inside a FrameLayout. But when I use ID of that it won't work either.
Any ideas?
-------main_board_layout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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/main_board"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#color/black"
android:orientation="vertical">
<android.inputmethodservice.KeyboardView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/keyboard_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black" />
<!--top bar-->
<View
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#ffffff"/>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#ffffff"
android:padding="2dp"
android:id="#+id/buttons"
>
<Button
android:id="#+id/b1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/button1" />
<Button
android:id="#+id/b2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:text="#string/button2"
/>
<TextView
android:id="#+id/packNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start"
android:text="#string/app_name"
android:textColor="#000000"
android:textSize="1sp"
android:visibility="gone"
/>
<ImageView
android:id="#+id/btShareLinkGP"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_gravity="center"
android:src="#mipmap/bt_share"
tools:srcCompat="#mipmap/bt_share"
/>
</FrameLayout>
<View
android:layout_width="match_parent"
android:layout_height="3dp"
android:background="#000000"/>
<ScrollView
android:id="#+id/gif_view"
android:layout_width="match_parent"
android:layout_height="190dp"
android:background="#color/black"
android:paddingLeft="0dp"
android:paddingRight="15dp" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#color/black"
android:gravity="left|center"
android:orientation="horizontal"
android:padding="0dp">
<android.support.v7.widget.RecyclerView
android:id="#+id/pack_recycler_view"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/black"
android:orientation="horizontal"
app:layoutManager="android.support.v7.widget.LinearLayoutManager" />
</LinearLayout>
</LinearLayout>
-------Stickers.java
public static String PACK_LIB ="";
public void setDefaultStickerPack() {
checkVersion(true);
InputStream in = null;
String packList[]=new String[0];
final String PACK_APP="pack_app";
final String PACK_ICON="pack_on.png";
String curAssets="";
-------KeyboardService.java
#Override
public View onCreateInputView() {
mainBoard = (LinearLayout) getLayoutInflater().inflate(R.layout.main_board_layout, null);
packNameLabel = (TextView) mainBoard.findViewById(R.id.packNameLabel);
scrollView = (ScrollView) mainBoard.findViewById(R.id.gif_view);
stickerView = (RecyclerView) getLayoutInflater().inflate(R.layout.recycler_view, null);
stickerView.addItemDecoration(new MarginDecoration(this));
stickerView.setHasFixedSize(true);
stickerView.setLayoutManager(new GridLayoutManager(this, 4));
scrollView.addView(stickerView);
ImageView btShareLinkGP = (ImageView) mainBoard.findViewById(R.id.btShareLinkGP);
btShareLinkGP.setOnClickListener(new View.OnClickListener() {
#Override
public void onClick(View view) {
shareLinkToGP();
}
});
// packs bar
packView = (RecyclerView) mainBoard.findViewById(R.id.pack_recycler_view);
// BUTTONS ACTIONS
final Button button1 = (Button) mainBoard.findViewById(R.id.b1);
button1.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "allstickers";
}
});
final Button button2 = (Button) mainBoard.findViewById(R.id.b2);
button2.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Stickers.PACK_LIB = "teststickers";
}
});
showStickers();
return mainBoard;
}
hi to everyone i have this code in xml and i want transform this to java
<TableRow>
<ImageButton android:id="#+id/btnImg1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="75dp"
android:src="#drawable/one"/>
<ImageButton android:id="#+id/btnImg2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:src="#drawable/two"/>
<ImageButton android:id="#+id/btnImg13"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="75dp"
android:src="#drawable/three"/>
</TableRow>
<TableRow>
<ImageButton android:id="#+id/btnImg4"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:src="#drawable/four"/>
<ImageButton android:id="#+id/btnImg5"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/five"/>
<ImageButton android:id="#+id/btnImg6"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/six"/>
</TableRow>
<TableRow>
<ImageButton android:id="#+id/btnImg7"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:src="#drawable/seven"
android:onClick="onClick"/>
<ImageButton android:id="#+id/btnImg8"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/eight"
android:onClick="onClick2"/>
<ImageButton android:id="#+id/btnImg9"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/nine"
android:onClick="onClick3"/>
</TableRow>
<TableRow>
<ImageButton android:id="#+id/btnImg10"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="80dp"
android:layout_marginTop="50dp"
android:src="#drawable/seven"/>
<ImageButton android:id="#+id/btnImg11"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:src="#drawable/eight"/>
<ImageButton android:id="#+id/btnImg12"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="50dp"
android:src="#drawable/nine"/>
</TableRow>
i write this in java but when i run all the imagebutton are duplicate on together:
public class GameActivity extends Activity {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// setContentView(R.layout.main);
LayoutParams params =
new TableRow.LayoutParams(
LayoutParams.WRAP_CONTENT,
LayoutParams.WRAP_CONTENT);
TableRow table = new TableRow(this);
table.setOrientation(TableRow.VERTICAL);
ImageButton ib = new ImageButton(this);
ib.setImageResource(R.drawable.one);
ib.setLayoutParams(params);
ib.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v){
Toast.makeText(getBaseContext(),"button clicked",Toast.LENGTH_SHORT).show();
}
});
ImageButton ib2 = new ImageButton(this);
ib.setImageResource(R.drawable.two);
ib.setLayoutParams(params);
ib.setOnClickListener(new View.OnClickListener()
{
public void onClick(View v){
Toast.makeText(getBaseContext(),"button clicked",Toast.LENGTH_SHORT).show();
}
});
table.addView(ib);
table.addView(ib2);
TableRow.LayoutParams layoutParams=
new TableRow.LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.MATCH_PARENT );
this.addContentView(table, layoutParams);
}
this is just for 2 imagebutton but this hapend too...thank you
I have a following layout in main_view.xml which contains a ImageButton in it, button when i click/touch the button the ButtonListener function never gets called.
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/relativeLayoutFragment"
android:layout_width="match_parent"
android:layout_height="fill_parent" >
<fragment
android:id="#+id/mapArea"
android:name="com.google.android.gms.maps.MapFragment"
android:layout_width="match_parent"
android:layout_height="match_parent" >
</fragment>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="horizontal" >
<TextView
android:id="#+id/locate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_gravity="center_horizontal"
android:layout_marginTop="10dp"
android:background="#80000000"
android:gravity="center"
android:padding="10dp"
android:text="#string/findingLocation"
android:textColor="#FFFFFF"
android:textSize="12sp" />
<ImageButton
android:id="#+id/Button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_marginBottom="#dimen/rightLeftMargin"
android:layout_marginLeft="#dimen/rightLeftMargin"
android:background="#null"
android:clickable="true"
android:contentDescription="#string/button1text"
android:src="#drawable/ic_feed_active" />
<ImageButton
android:id="#+id/Button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="#dimen/rightLeftMargin"
android:background="#null"
android:contentDescription="#string/button2"
android:src="#drawable/ic_button2" />
<ImageButton
android:id="#+id/Button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="#dimen/rightLeftMargin"
android:layout_marginRight="#dimen/rightLeftMargin"
android:background="#null"
android:contentDescription="#string/button3View"
android:src="#drawable/ic_settings_active" />
</RelativeLayout>
And following code in MainActivity.Java
public class MainActivity extends Activity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
User usrObj = new User();
if (usrObj.authenticateUser())
setContentView(R.layout.main_view);
else
setContentView(R.layout.login);
}
public void ButtonListener() {
ImageButton oggleButton = (ImageButton) findViewById(R.id.Button1);
ToggleButton.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View arg0) {
Toast.makeText(MainActivity.this, "ImageButton is clicked!",
Toast.LENGTH_SHORT).show();
}
});
}
}
please help.
you forget to call ButtonListener method when usrObj.authenticateUser() is true. do it as:
if (usrObj.authenticateUser())
{
setContentView(R.layout.main_view);
ButtonListener (); << call here
}
else
setContentView(R.layout.login);
and also attach setOnClickListener to oggleButton instead of ToggleButton
apart from above suggestions from ρяσѕρєя K, here is one more thing you have to take care is.
instead of this below code.
oggleButton.setOnClickListener(new OnClickListener() {
use this one
oggleButton.setOnClickListener(new View.OnClickListener() { // use View.oncli......
I'd like to create a menu for my widget configuration similar like GWT Stack Panel
Is it posible to create similar type of Menu in android.? Any Help or suggestions are welcome.
use this layout :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<Button
android:text="Bt1"
android:id="#+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearLayout1">
<ImageView
android:layout_width="wrap_content"
android:id="#+id/imageView1"
android:layout_height="wrap_content"
android:src="#drawable/icon"></ImageView>
</LinearLayout>
<Button
android:text="Bt2"
android:id="#+id/button2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearLayout2">
<ImageView
android:layout_width="wrap_content"
android:id="#+id/imageView2"
android:layout_height="wrap_content"
android:src="#drawable/icon"></ImageView>
</LinearLayout>
<Button
android:text="Bt3"
android:id="#+id/button3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"></Button>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:id="#+id/linearLayout3">
<ImageView
android:layout_width="wrap_content"
android:id="#+id/imageView3"
android:layout_height="wrap_content"
android:src="#drawable/icon"></ImageView>
</LinearLayout>
</LinearLayout>
and use this code :
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
findViewById(R.id.linearLayout1).setVisibility(View.GONE);
findViewById(R.id.linearLayout2).setVisibility(View.GONE);
findViewById(R.id.linearLayout3).setVisibility(View.GONE);
Button bt1=(Button) findViewById(R.id.button1);
Button bt2=(Button) findViewById(R.id.button2);
Button bt3=(Button) findViewById(R.id.button3);
bt1.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
findViewById(R.id.linearLayout1).setVisibility(View.VISIBLE);
findViewById(R.id.linearLayout2).setVisibility(View.GONE);
findViewById(R.id.linearLayout3).setVisibility(View.GONE);
}
});
bt2.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
findViewById(R.id.linearLayout1).setVisibility(View.GONE);
findViewById(R.id.linearLayout2).setVisibility(View.VISIBLE);
findViewById(R.id.linearLayout3).setVisibility(View.GONE);
}
});
bt3.setOnClickListener(new OnClickListener() {
#Override
public void onClick(View v) {
findViewById(R.id.linearLayout1).setVisibility(View.GONE);
findViewById(R.id.linearLayout2).setVisibility(View.GONE);
findViewById(R.id.linearLayout3).setVisibility(View.VISIBLE);
}
});
}
you can use your layout in the linearlayout1,linearlayout2 and linearlayout3 for build stack panel for android.