I am trying to display array items in ListView using ArrayAdapter. it's not showing any items in ListView and not showing any error's below is my java class and xml.
package church.llagc.com;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
public class listView extends AppCompatActivity {
ArrayAdapter<String> adapter;
String[] alphabitlist = {"A","Aa","I","EE","U","Uu","E","EI","O","Oo","Ka","Ga","Cha","Ja","Tha","Da","Na","Pa","Ba",
"Bha","Ma","Ya","Ra","La","Va","Ssa","Sha","Sa","Ha"};
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_list_view);
adapter= new ArrayAdapter<String>(this,android.R.layout.simple_list_item_1,alphabitlist);
ListView alpabits = (ListView) findViewById(R.id.alphabitorder);
alpabits.setAdapter(adapter);
}
}
containt_main.xml
<?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"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="church.llagc.com.MainActivity"
tools:showIn="#layout/app_bar_main">
<include layout="#layout/activity_list_view"/>
</android.support.constraint.ConstraintLayout>
and my activity_list_view.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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
tools:context="church.llagc.com.listView">
<ListView
android:background="#drawable/alphabit_bg"
android:id="#+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="#+id/itemcontent"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="8"/>
</LinearLayout>
Please comment if you have any doubts.
Do not use android.R.layout.simple_list_item_1 and create you own layout file. This android.R.layout.simple_list_item_1 layout file has a simple text view but the text color is something related to white that's why you cant see it. Now you have to create a new layout file which contain only text view and set text color and pass it to your adapter
Try this.
<ListView
android:background="#drawable/alphabit_bg"
android:id="#+id/alphabitorder"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:scrollbars="none"/>
<ListView
android:id="#+id/itemcontent"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="8"/>
</LinearLayout>
Related
I'm setting up a bottom navigation for my app. I want to set/customize the actions for the menus but I'm facing an issue in the code. It can not find the id 'bottomNavView_bar' of the bottomnavigationview. I'm getting the error "Can't resolve symbol 'bottomNavView_bar'"
Here is my activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout
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">
<!--parent relative layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/parent_relative_layout">
<!--top bar layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/relLayoutTopbar">
<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
>
<com.google.android.material.tabs.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/tabs">
</com.google.android.material.tabs.TabLayout>
</com.google.android.material.appbar.AppBarLayout>
</RelativeLayout>
<!--middle layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/relLayoutMiddle"
android:layout_below="#id/relLayoutTopbar"
android:background="#color/mainbackgroud">
<!--view pager-->
<androidx.viewpager.widget.ViewPager
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="#+id/homecontainer">
</androidx.viewpager.widget.ViewPager>
</RelativeLayout>
<!--bottom bar layout-->
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="50dp"
android:id="#+id/relLayoutBottombar"
android:layout_alignParentBottom="true">
<com.google.android.material.bottomnavigation.BottomNavigationView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/bottomNavView_bar"
app:itemBackground="#color/bgBottomNavigation"
android:foreground="?attr/selectableItemBackground"
app:itemIconTint="#android:color/white"
app:itemTextColor="#android:color/white"
app:menu="#menu/bottom_navigation_menu">
</com.google.android.material.bottomnavigation.BottomNavigationView>
</RelativeLayout>
</RelativeLayout>
</androidx.coordinatorlayout.widget.CoordinatorLayout>
Here's the menu file bottom_navigation_menu.xml
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="#+id/navigation_shop"
android:icon="#drawable/news"
android:title="#string/title_home" />
<item
android:id="#+id/navigation_games"
android:icon="#drawable/hockeystick"
android:title="#string/title_games" />
<item
android:id="#+id/navigation_stats"
android:icon="#drawable/graphic"
android:title="#string/title_stats" />
<item
android:id="#+id/navigation_settings"
android:icon="#drawable/settings"
android:title="#string/title_settings" />
</menu>
here is part of my MainActivity.java
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.viewpager.widget.ViewPager;
import android.os.Bundle;
import android.view.MenuItem;
import com.google.android.material.tabs.TabLayout;
import com.google.android.material.bottomnavigation.BottomNavigationView;
public class MainActivity extends AppCompatActivity {
private static final String TAG = "MainActivity";
private SectionsPagerAdapter mSectionsPagerAdapter;
private ViewPager mViewPager;
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
getSupportActionBar().setElevation(0);
mSectionsPagerAdapter = new
SectionsPagerAdapter(getSupportFragmentManager());
mViewPager = findViewById(R.id.homecontainer);
setupViewPager(mViewPager);
TabLayout tabLayout = findViewById(R.id.tabs);
tabLayout.setupWithViewPager(mViewPager);
tabLayout.getTabAt(0).setIcon(R.drawable.ic_rss_feed);
tabLayout.getTabAt(1).setIcon(R.drawable.ic_alarm);
//bottom navigation bar
BottomNavigationView navigation =
(BottomNavigationView)findViewById(R.id.bottomNavView_bar); //trying to get the view id here
BottomNavigationViewHelper.disableShiftMode(navigation);
}
Select tools>-android>-SDK manager
and download the SDK build tools, SDK platform and Google API's( the Google API stores packages such as "import android.view.Menu" etc.) for the target SDK version of your project(20 as shown in your screenshot). if you are not sure which items you have to download, you can select all of them. (will take more time to download of course).
Restart the IDE
http://is4.mzstatic.com/image/thumb/Purple1/v4/8f/96/0e/8f960eda-413d-c1c2-fcf0-178e9206fbe2/source/392x696bb.jpg
I want to make an empty gridview like the image above. I created grid view in xml:
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
android:orientation="vertical" >
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/gridview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:numColumns="90"
android:verticalSpacing="10dp"
android:horizontalSpacing="10dp"
android:stretchMode="columnWidth"
android:gravity="center"
android:background="#000"
/>
</FrameLayout>
Then I created grid view object in my activity
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_painting);
GridView gridView = (GridView) findViewById(R.id.gridview);
}
But I can't see the borders. Also I can't see any cell and can't click as expected.
How can I create a grid view with empty cells, also with borders.
Thanks in advance.
i'm building an android app using Android Studio and I want to display my items(images-using imageViews) in rows(4 in each one) but when I add more than 4 items, instead of the next item been taken to the next row, it just doesn't show up at all. What am I missing? I tried tweaking multiple things but none of it worked. Keep in mind that i'm new to android app development so i'm not sure if my layout choices are "optimal".Below you will find my xml file that handles all of the layout parts:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout 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.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="100dp"
android:padding="20dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:text="Cards List"
android:textColor="#android:color/holo_blue_light"
android:textSize="40sp" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<android.support.v4.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="android.support.design.widget.AppBarLayout$ScrollingViewBehavior">
<android.support.v7.widget.LinearLayoutCompat
android:id="#+id/relativeLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_centerVertical="true"
android:verticalSpacing="10dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:paddingBottom="500dp"
android:stretchMode="columnWidth"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:verticalSpacing="10dp">
</GridView>
</LinearLayout>
</android.support.v7.widget.LinearLayoutCompat>
</android.support.v4.widget.NestedScrollView>
</android.support.design.widget.CoordinatorLayout>
MAINACTIVITY.JAVA
package com.example.steli.hellogridview;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.GridView;
import android.widget.Toast;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView gridView = (GridView) findViewById(R.id.gridView);
gridView.setAdapter(new ImageAdapter(this));
gridView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> adapterView, View view, int position, long id) {
Toast.makeText(MainActivity.this,"" + position,Toast.LENGTH_SHORT).show();
}
});
}
}
IMAGEADAPTER.JAVA
package com.example.steli.hellogridview;
import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridLayout;
import android.widget.GridView;
import android.widget.ImageView;
import android.widget.ListAdapter;
/**
* HelloGridView was
* Created by Stelios Papamichail on 11/5/2017.
*
* This file belongs to the com.example.steli.hellogridview package.
*/
public class ImageAdapter extends BaseAdapter {
private Context mContext;
public ImageAdapter(Context c) {
mContext = c;
}
public int getCount() {
return mThumbIds.length;
}
public Object getItem(int position) {
return null;
}
public long getItemId(int position) {
return 0;
}
// Create a new ImageView for each item referenced by the Adapter
#Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageView;
if(convertView == null) {
// If it's not recycled, initialize some attributes
imageView = new ImageView(mContext);
imageView.setLayoutParams(new GridView.LayoutParams(180,180));
imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageView.setPadding(8,8,8,8);
} else {
imageView = (ImageView) convertView;
}
imageView.setImageResource(mThumbIds[position]);
return imageView;
}
// references to our images
private Integer[] mThumbIds = {
R.drawable.ssj4_gogeta,
R.drawable.cell_jr_n,
R.drawable.mrsatan_n,
R.drawable.tien,
R.drawable.vegito,
R.drawable.videl
};
}
There is nothing wrong with your Java code. Your XML, however, is pretty messed up.
Why, for example, do you cascade a LinearLayout inside a LinearLayoutCompat inside a NestedScrollView? For scrolling the GridView, you don't need any of this. So take it out.
Also, android:paddingBottom="500dp" is too much. This line pushes part of your GridView outside the top of the screen (at least on the emulator I use). So get rid of that, too (or make the padding smaller).
I don't understand what you want with the AppBarLayout, so I leave it untouched.
Since you probably don't want the GridView to render on top of it, I put the AppBarLayout and the GridView inside a RelativeLayout with android:layout_below="#id/appbar" inside the GridView's XML.
So the XML now looks like this:
<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.design.widget.AppBarLayout
android:id="#+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="20dp">
<android.support.design.widget.CollapsingToolbarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:contentScrim="?attr/colorPrimary"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:toolbarId="#+id/toolbar">
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="70dp"
android:text="Cards List"
android:textColor="#android:color/holo_blue_light"
android:textSize="40sp" />
<android.support.v7.widget.Toolbar
android:id="#+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"></android.support.v7.widget.Toolbar>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<GridView
android:id="#+id/gridView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#id/appbar"
android:columnWidth="90dp"
android:gravity="center"
android:horizontalSpacing="10dp"
android:numColumns="4"
android:stretchMode="columnWidth"
android:theme="#style/Theme.AppCompat.Light.NoActionBar"
android:verticalSpacing="10dp">
</GridView>
</RelativeLayout>
</android.support.design.widget.CoordinatorLayout>
I'm trying to make a color picker application by using Recyclerview and GridlayoutManager for listing the colors. I am using ImageButton for presenting the colors. There are two recyclerviews, first one displays main colors that i made up and the second one displays the tint and shadow of the selected color from the first one. My code is ugly but this is for experimenting so right now i just want to make the second recyclerview with gridlayoutmanager be in two rows and 4 columns. I could make it with the code below but it only shows the first 4 colors and for the other ones i have to scroll down the view.
MainActivity:
package tr.com.beyes.colorpicker;
import android.content.res.Resources;
import android.graphics.Color;
import android.support.v4.content.res.TypedArrayUtils;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.widget.Toast;
import java.util.ArrayList;
public class MainActivity extends AppCompatActivity {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
Resources r=getResources();
int[] fontColors = r.getIntArray(R.array.fontcolors);
RecyclerView recyclerView = (RecyclerView) findViewById(R.id.fontColorView);
GridLayoutManager gridLayoutManager = new GridLayoutManager(this,11, GridLayoutManager.VERTICAL, true);
recyclerView.setLayoutManager(gridLayoutManager);
RecyclerView recyclerView2 = (RecyclerView) findViewById(R.id.fontColorViewSub);
GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this,4);
recyclerView2.setLayoutManager(gridLayoutManager2);
int[] tint = new int[8];
tint[0]=(Color.rgb(0,0,0));
int red = Color.red(fontColors[0]);
int green = Color.green(fontColors[0]);
int blue = Color.blue(fontColors[0]);
for(int i=1; i<7;i++){
red = (int) (red + (255-red) * 0.25);
green = (int) (green + (255-green) * 0.25);
blue = (int) (blue + (255-blue) * 0.25);
tint[i]=(Color.rgb(red,green,blue));
}
tint[7]=(Color.rgb(255,255,255));
ColorPickerAdapter colorPickerAdapter2 = new ColorPickerAdapter(tint,this, null);
recyclerView2.setAdapter(colorPickerAdapter2);
ColorPickerAdapter colorPickerAdapter = new ColorPickerAdapter(fontColors,this,colorPickerAdapter2);
recyclerView.setAdapter(colorPickerAdapter);
}
}
Activity_main.xml
<?xml version="1.0" encoding="utf-8"?>
<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: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="tr.com.beyes.colorpicker.MainActivity"
android:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorView"
>
</android.support.v7.widget.RecyclerView>
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorViewSub"
android:layout_marginTop="20dp"
>
</android.support.v7.widget.RecyclerView>
</LinearLayout>
colorbox.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageButton
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="24dp"
android:id="#+id/fontColorBox"
android:clickable="true"
/>
</LinearLayout>
1. Use setHasFixedSize(true) to recyclerView and recyclerView2
2. Update gridLayoutManager2 parameter as below:
GridLayoutManager gridLayoutManager2 = new GridLayoutManager(this, 4, GridLayoutManager.VERTICAL, true);
3. Use NestedScrollView as a container of your LinearLayout.
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="#string/appbar_scrolling_view_behavior"
tools:context="tr.com.beyes.colorpicker.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
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:orientation="vertical">
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorView" />
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/fontColorViewSub"
android:layout_marginTop="20dp" />
</LinearLayout>
</android.support.v4.widget.NestedScrollView>
Hope this will work~
I'm working with android studio and I have this list and I can't get the layout to work.(You'll notice I have a listener that opens another activity when you click on a single item, and that works just fine).
Here's my activity_estoque.xml file:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
</LinearLayout>
and this is the estoque.java class, that uses the .xml file above:
package com.example.asus.mingausfashionmoda;
import android.app.Activity;
import android.app.ListActivity;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ArrayAdapter;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
public class estoque extends ListActivity {
#Override
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
//string que pega do query
String[] adobe_products = {"SANSUMG", "LG", "MOTOROLA", "Apple"};
this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_estoque, R.id.label, adobe_products));
ListView lv = getListView();
//listening to single item in list view
lv.setOnItemClickListener(new AdapterView.OnItemClickListener() {
#Override
public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
//selected item
LinearLayout ll = (LinearLayout) view;
TextView tv = (TextView) ll.findViewById(R.id.label);
final String product = tv.getText().toString();
//String product = ((TextView) view).getText().toString();
//lauching new activity to single item
Intent i = new Intent(getApplicationContext(), estoqueSingle.class);
//sending data to new activity
i.putExtra("product", product);
startActivity(i);
}
});
}
}
I added some pictures to help you understand what I want and what I'm getting(sorry for bad paiting):
1 - The screen on the left is what I should see, according to the Android Studio activity_estoque.xml Design session, and the right one is what I actually get(Notice the "Mingau's fashion moda" thing missing, I really want this blue thing): (What I should get vs what I'm getting)
2 - Now, the left screen is what I want, a top single button and the list bellow. The right one is what I'm receiving after adding a button on the activity_estoque.xml file(code bellow): (What I want vs what I get)
this is the activity_estoque.xml file after I add the button:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10dip"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnttt"
android:text="This is a button"
/>
</LinearLayout>
First I thought that I should add a setContentView(R.layout.activity_estoque); on the onCreat method, like this:
protected void onCreate (Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_estoque);
//string que pega do query
String[] adobe_products = {"SANSUMG", "LG", "MOTOROLA", "Apple"};
but if I do that I get the following error, and I'm not sure if it makes any sense to add this setContentView...:
java.lang.RuntimeException: Unable to start activity ComponentInfo{com.example.asus.mingausfashionmoda/com.example.asus.mingausfashionmoda.estoque}: java.lang.RuntimeException: Your content must have a ListView whose id attribute is 'android.R.id.list'
and this:
at com.example.asus.mingausfashionmoda.estoque.onCreate(estoque.java:20)
this is what I have on estoque.java.20:
setContentView(R.layout.activity_estoque);
Anyone can help? Thanks.
What you want to achieve is explained here as example here. And the blue bar above you see is actually achievable using Action Bar example here. This action bar is configurable for color, icon, title, sub title and the menus(show/not to show).
You are extending a ListActivity, so when you start the activity it will use the default layout. If you try to do setContentView(R.layout.activity_estoque); in the code then the activity will expect your layout to hava list view with the id "list".
Edit--
Change your layout to
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="10dip"
android:textSize="16sp"
android:textStyle="bold" >
</TextView>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnttt"
android:text="This is a button"
/>
<ListView android:id="#android:id/list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#00FF00"
android:layout_weight="1"
android:drawSelectorOnTop="false"/>
</LinearLayout>
and
and do setContentView(R.layout.activity_estoque) in onCreate
You will need to create a new layout for your list item view, which you need to pass to the ArrayAdapter
For eg:
activity_test.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="#+id/label1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
then change this this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_estoque, R.id.label, adobe_products)); to this.setListAdapter(new ArrayAdapter<String>(this, R.layout.activity_test, R.id.label1, adobe_products));