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.
Related
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>
I'm trying to fill the page by blocks of linearlayout by data. Also I'm using ViewPager for changing pages. Every page should have its own data blocks, but now I'm getting linearlayouts that doesn't swipes out (blocks stand still when I'm swiping pages) but there is another linearlayout right above the other ones that doesn't constist data but sliding when I swipe pages.
main.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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<android.support.v4.view.ViewPager
android:id="#+id/page"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
</android.support.v4.view.ViewPager>
<LinearLayout
android:orientation="vertical"
android:id="#+id/page_blocks"
android:layout_width="fill_parent"
android:layout_height="wrap_content">
</LinearLayout>
</RelativeLayout>
table_row:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/program_frame"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:padding="5dip">
<TextView
android:id="#+id/StudyName"
/>
<TextView
android:id="#+id/Auditorium"
/>
<TextView
android:id="#+id/StudyKindName"
/>
<TextView
android:id="#+id/LectureTitle"
/>
<ImageView
android:id="#+id/imageView2"
/>
</RelativeLayout>
onCreateView of ViewPage:
#Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View view = inflater.inflate(R.layout.table_row, null);
framesContainer = (LinearLayout) getActivity().findViewById(R.id.page_blocks);
for (int i = 0; i < 16; i += 4) {
Frame frame = new Frame(getActivity());
try {
frame.setStudyName(s.get().get(0).Days().get(i));
frame.setStudyKindName(s.get().get(0).Days().get(i + 1));
frame.setAuditorium(s.get().get(0).Days().get(i + 2));
frame.setLectureTitle(s.get().get(0).Days().get(i + 3));
framesContainer.addView(frame);
} catch (Exception e) {
e.printStackTrace();
}
}
return view;
}
Also pic:
Is there a way to hide the empty block and make all blocks slide after the page when swiping?
Your problem is that you are using RelativeLayouts, and since you are not aligning its children elements(ViewPager and LinearLayout), they are overlapping:
<?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:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MyActivity">
<android.support.v4.view.ViewPager
android:id="#+id/page"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<LinearLayout
android:orientation="vertical"
android:id="#+id/page_blocks"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#id/page" >
</LinearLayout>
This line tells the viewpager that its position is going to be at the top of the RelativeLayout:
android:layout_alignParentTop="true"
And this one tells the LinearLayout its position is below the viewpager:
android:layout_below="#id/page"
There are some other properties that can be set --> RelativeLayout
To be honest, I'm not sure what you are trying to do. But maybe you just need to get rid of the RelativeLayout and use LinearLayouts instead.
This is my XML file for creating a horizontal gridview:
<?xml version="1.0" encoding="utf-8"?>
<HorizontalScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/change_frame_scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="match_parent" >
<GridView
android:id="#+id/change_frame_gridview"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:stretchMode="columnWidth"
android:scrollbars="horizontal"
android:padding="10dp" />
</FrameLayout>
</HorizontalScrollView>
And here is how to implement in Activity:
gridView = (GridView) v.findViewById(R.id.change_frame_gridview);
gridView.setAdapter(adapter);
gridView.setNumColumns(adapter.getCount());
gridView.setOnItemClickListener(this);
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(
(adapter.getItemWidth() + FrameThumbnailAdapter.ITEM_MARGIN) * adapter.getCount(),
LayoutParams.WRAP_CONTENT);
gridView.setLayoutParams(params);
gridView.requestFocus();
gridView.setSelection(10);
adapter.notifyDataSetChanged();
But the selection(10) does not work.
Hey, I want to change the TypeFace of one of the TextViews to an external font.. How can I do that?
Code:
public class English extends Activity {
<...>
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.quran_english);
listview=(ListView) findViewById(R.id.QuranEnglishListView);
<..add into list..>
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.quran_english_row,
new String[] {"Arabic","English"},
new int[] {R.id.QuranEnglishTextViewArabic,R.id.QuranEnglishTextViewEnglish});
listview.setAdapter(adapter);
xml for each row (quran_english_row.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout android:gravity="right" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="fill_parent">
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewArabic" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewEnglish" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
xml for the layout (quran_english.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:id="#+id/QuranEnglishListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
</LinearLayout>
This crashes because of NullPointer:
((TextView) findViewById(R.id.QuranEnglishTextViewArabic)).setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
So how can I reach the TextView that is in the row to change its TypeFace? Thanks
You can try to get the layout for each list item by
View rowView = adapter.getView(...);
Then get the TextView of the layout by
TextView txt = (TextView)rowView .findViewById(R.id.QuranEnglishTextViewEnglish);
txt.setTypeFace(...);
and set your TypeFaces. Haven't tested that yet, but i guess it could work.
But I recommend extending your own BaseAdapter. Then create another list-row class which provides the inflated layouts for your BaseAdapter. There you'll be able to set the typefaces easily for every TextView.
try this links it works http://techdroid.kbeanie.com/2011/04/using-custom-fonts-on-android.html see steps and class MyTextView and MyButton shown above layout
I have a ListView that uses SimpleAdapter, each row has 2 TextViews, and I would like to use an external font to one of the two TextView.. Here is the code of the class:
public class QuranEnglish extends Activity {
<...>
#Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.quran_english);
listview=(ListView) findViewById(R.id.QuranEnglishListView);
<..add into list..>
SimpleAdapter adapter = new SimpleAdapter(
this,
list,
R.layout.quran_english_row,
new String[] {"Arabic","English"},
new int[] {R.id.QuranEnglishTextViewArabic,R.id.QuranEnglishTextViewEnglish});
listview.setAdapter(adapter);
xml for each row (quran_english_row.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<LinearLayout android:gravity="right" android:layout_height="wrap_content" android:id="#+id/linearLayout1" android:layout_width="fill_parent">
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewArabic" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
<TextView android:textSize="21px" android:text="TextView" android:id="#+id/QuranEnglishTextViewEnglish" android:layout_width="wrap_content" android:layout_height="wrap_content"></TextView>
</LinearLayout>
xml for the layout (quran_english.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" android:orientation="vertical">
<ListView android:id="#+id/QuranEnglishListView" android:layout_width="fill_parent" android:layout_height="fill_parent"></ListView>
</LinearLayout>
So how can I put the external typeface of the TextView that is in the row (quran_english_row.xml)? I tried using this line though it crashed my application:
((TextView) findViewById(R.id.QuranEnglishTextViewArabic)).setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
R.id.QuranEnglishTextViewArabic
is not an id of one of your views here. It is an id of a example view, which is used to fill the list. In order to change the font, you need to get one view of your list. This works if you have chosen one of your views:
TextView view = getSelectedView();
if (view != null) {
view.setTypeface(Typeface.createFromAsset(getAssets(),"dejavusans.ttf"));
}