我想顯示空白動態網格這樣Android系統如何顯示空白的GridView與按鈕
我試圖填充電網這樣的,但是爲了這個,我需要繪製int數組發送到baseadapter.I知道它要做到這一點
不正確的方式請考慮以下情形:
1)用戶將獲得這種屏幕與「+」按鈕,將圖片添加到電網和空白格「 - 」按鈕,如果圖像存在於網格
上2)只要用戶填入GridView的倒數第二個空白網格,即可動態增加網格。
考慮這個問題太Alternate Question
我想顯示空白動態網格這樣Android系統如何顯示空白的GridView與按鈕
我試圖填充電網這樣的,但是爲了這個,我需要繪製int數組發送到baseadapter.I知道它要做到這一點
不正確的方式請考慮以下情形:
1)用戶將獲得這種屏幕與「+」按鈕,將圖片添加到電網和空白格「 - 」按鈕,如果圖像存在於網格
上2)只要用戶填入GridView的倒數第二個空白網格,即可動態增加網格。
考慮這個問題太Alternate Question
我已經創造了這一問題的虛方法(要添加修改GridView的動態):
創建活動Main3Activity
public class Main3Activity extends AppCompatActivity implements ViewClickCallBack {
private RecyclerView recyclerView;
private GridAdapter gridAdapter;
private List<Model> models = new ArrayList<>();
private final int SIZE_NEXT_ITEM = 5;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main3);
recyclerView = (RecyclerView) findViewById(R.id.grid_recycle);
gridAdapter = new GridAdapter(this);
getNextModel();
gridAdapter.setModels(models);
RecyclerView.LayoutManager mLayoutManager = new GridLayoutManager(this, 3);
recyclerView.setLayoutManager(mLayoutManager);
recyclerView.setAdapter(gridAdapter);
}
@Override
public void viewClicked(int position) {
models.get(position - 1).setUploaded(true);// Set the upload flag as true for the clicked item
int gridItemCount = gridAdapter.getItemCount();// Get the total count of items in gridview
if ((gridItemCount - position) == 1) { // check if the clicked item is second last, if yes then difference would be 1
getNextModel();
gridAdapter.setModels(models);
} else {
Toast.makeText(this, "Popup Image picker", Toast.LENGTH_SHORT).show();
}
gridAdapter.notifyDataSetChanged();
}
/**
* Function to get the set (or next set) of objects that
* we want to show in GRID view.
*
* These objects will be added to a list.
* This list will act as data source for adapter
**/
private void getNextModel() {
for (int i = 0; i < SIZE_NEXT_ITEM; i++) {
Model model = new Model();
model.setUploaded(false);
models.add(model);
}
}
}
XML作爲activity_main3
<?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"
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="work.sof.ghost.myapplication.Main3Activity">
<android.support.v7.widget.RecyclerView
android:id="@+id/grid_recycle"
android:layout_width="match_parent"
android:layout_height="wrap_content"/>
</RelativeLayout>
的適配器說GridAdapter
public class GridAdapter extends RecyclerView.Adapter<GridAdapter.GridViewHolder> {
private ViewClickCallBack viewClickCallBack;
private List<Model> models;
public GridAdapter(ViewClickCallBack viewClickCallBack) {
this.viewClickCallBack = viewClickCallBack;
}
class GridViewHolder extends RecyclerView.ViewHolder {
public TextView textView;
public GridViewHolder(View itemView) {
super(itemView);
textView = (TextView) itemView.findViewById(R.id.text_some);
textView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (viewClickCallBack != null) {
Log.e("Element Index", "" + getAdapterPosition());
/**
* Increment the position by 1, as getAdapterPosition will
* return the index (count starts from 0) of the element.
* Hence, to simplify, we will increment the index by one,
* so that when we calculate the second last element, we will
* check the difference for 1.
* */
viewClickCallBack.viewClicked(getAdapterPosition() + 1);
}
}
});
}
}
@Override
public GridViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext())
.inflate(R.layout.grid_view, parent, false);
return new GridViewHolder(itemView);
}
@Override
public void onBindViewHolder(GridViewHolder holder, int position) {
Model model = getModel(position);
if (model.isUploaded()) {
holder.textView.setText("-");
} else {
holder.textView.setText("+");
}
}
@Override
public int getItemCount() {
if (models != null) {
return models.size();
}
return 0;
}
private Model getModel(int position) {
if (models != null) {
return models.get(position);
}
return null;
}
public void setModels(List<Model> models) {
this.models = models;
}
}
的模型類模型
public class Model {
private String imagePath;
private boolean isUploaded;
public String getImagePath() {
return imagePath;
}
public void setImagePath(String imagePath) {
this.imagePath = imagePath;
}
public boolean isUploaded() {
return isUploaded;
}
public void setUploaded(boolean uploaded) {
isUploaded = uploaded;
}
}
一種用於網格視圖佈局(我知道如圖問題:(其不相同)
<?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:layout_marginBottom="5dp"
android:layout_marginRight="5dp"
android:background="@drawable/rect_drawable"
android:orientation="vertical">
<ImageView
android:src="@drawable/ic_launcher"
android:id="@+id/image_holder"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_gravity="right"
android:id="@+id/text_some"
android:layout_margin="10dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="25sp"
android:text="+" />
</LinearLayout>
drawabl Ë文件rect_drawable
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android" android:shape="rectangle">
<size
android:width="6dp"
android:height="6dp" />
<solid android:color="@color/colorPrimary" />
</shape>
關於復問題
「如何將多個圖像通過的AsyncTask儘快發送給服務器用戶按下保存或完成按鈕」:
使用
a)executeOnExecutor(java.util.concurrent.Executor,Object []) with THREAD_POOL_EXECUTOR。要發送1幅圖像每異步任務並行, 更多信息以https://developer.android.com/reference/android/os/AsyncTask.html
或
郵政UI你有什麼代碼嘗試到目前爲止 – avinash
@avinash我已經做了簡單的片段與RecyclerView(網格佈局) 首先我想實現上面的空白布局,自動增加,只要用戶填寫第二最後一個。然後用戶可以用相機或本地gallery填充這些網格。我當前的代碼很簡單RecyclerView與網格佈局 – androidXP