0
我想構建一個android應用程序,我有一個3列gridview顯示點的列表,我想跳轉到條件中的下一行,即使某些列是空跳過項目Android網格視圖條件
例子我想做的事情是這樣的:
ARX ARH
BRH BRX BRY
CRH
DRH DRY
我想構建一個android應用程序,我有一個3列gridview顯示點的列表,我想跳轉到條件中的下一行,即使某些列是空跳過項目Android網格視圖條件
例子我想做的事情是這樣的:
ARX ARH
BRH BRX BRY
CRH
DRH DRY
試試這個
您的列表項行XML會是這樣 Abc.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@android:color/darker_gray">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_margin="5dp">
<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name1"
android:textSize="18sp"
android:background="@android:color/white"
android:layout_margin="5dp"/>
<TextView
android:id="@+id/textView2"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name2"
android:textSize="18sp"
android:layout_margin="5dp"
android:background="@android:color/white"/>
<TextView
android:id="@+id/textView3"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_weight="1"
android:gravity="center"
android:text="Name3"
android:textSize="18sp"
android:layout_margin="5dp"
android:background="@android:color/white"/>
</LinearLayout>
</LinearLayout>
而且CustomAdapter的名單會是這樣
public class Custom_Adapter_Products extends BaseAdapter {
Context context;
String[] list = {"AAA","AAA","AAA","AAA","AAA","","AAA", "AAA","AAA"};
public Custom_Adapter_Products(Context context){
this.context = context;
}
@Override
public int getCount() {
return (list.length/3);
}
@Override
public Object getItem(int position) {
return null;
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int pos, View convertView, ViewGroup parent) {
try{
int position = (pos*3);
ViewHolder holder;
LayoutInflater vi = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
if (convertView == null)
{
convertView = vi.inflate(R.layout.abc, null);
holder = createViewHolder(convertView);
convertView.setTag(holder);
}
else
{
holder = (ViewHolder) convertView.getTag();
}
if(!list[position].equals("")){
holder.textView1.setText(list[position]);
holder.textView1.setVisibility(View.VISIBLE);
}
else{
holder.textView1.setVisibility(View.GONE);
}
if(!list[position+1].equals("")){
holder.textView2.setText(list[position]);
holder.textView2.setVisibility(View.VISIBLE);
}
else{
holder.textView2.setVisibility(View.GONE);
}
if(!list[position+2].equals("")){
holder.textView3.setText(list[position]);
holder.textView3.setVisibility(View.VISIBLE);
}
else{
holder.textView3.setVisibility(View.GONE);
}
}catch (Exception e){
e.printStackTrace();
}
return convertView;
}
private static class ViewHolder
{
public TextView textView1;
public TextView textView2;
public TextView textView3;
}
private ViewHolder createViewHolder(View v) {
ViewHolder holder = new ViewHolder();
try{
holder.textView1 = (TextView) v.findViewById(R.id.textView1);
holder.textView2 = (TextView) v.findViewById(R.id.textView2);
holder.textView3 = (TextView) v.findViewById(R.id.textView3);
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
return holder;
}
}
是它的GridView強制使用或者我們可以用ListView的管理? –
是的,我們可以使用Listview管理任何解決方案嗎? –
是的,我有一個解決方案....看到我的帖子作爲答案。 –