如果n为4,我想在列表视图或回收站视图中添加n个微调器,4个微调器应该在其中包含不同的项目。 我尝试过使用Recycler视图,但正如它的名字所说它回收视图,我不认为可以添加更多视图(我不确定)。以下是我的代码
public class Online3 extends AppCompatActivity {
List<String> categories1, categories2, categories3, categories4, categories13, categories12, categories5, categories6;
String objectId;
private List<Array_G_S> list = new ArrayList<>();
RecyclerView recyclerView;
ArrayAdap adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_online3);
Intent intent = getIntent();
objectId = intent.getStringExtra("objId");
String txt = intent.getStringExtra("imageText");
if (objectId != null) {
Log.i("sand", objectId);
} else {
Log.i("sand", txt);
}
new RemoteTask().execute();
}
private class RemoteTask extends AsyncTask<Void, Void, Void> {
@Override
protected Void doInBackground(Void... params) {
ParseQuery<ParseObject> query = new ParseQuery<>("OnlineShopping");
query.whereEqualTo("objectId", objectId);
List<ParseObject> object1 = null;
try {
object1 = query.find();
for (final ParseObject country : object1) {
if (country != null) {
ParseRelation<ParseObject> p = country.getRelation("arrayRelation");
ParseQuery p2 = p.getQuery();
List<ParseObject> oc = p2.find();
for (ParseObject country2 : oc) {
if (country2 != null) {
categories1 = country2.getList("eType");
Array_G_S gs = new Array_G_S();
gs.setStringList(categories1);
list.add(gs);
}
}
}
// Locate images in flag column
}
} catch (com.parse.ParseException e1) {
e1.printStackTrace();
}
return null;
}
@Override
protected void onPostExecute(Void aVoid) {
recyclerView = (RecyclerView) findViewById(R.id.arrayRecy);
recyclerView.setNestedScrollingEnabled(false); // Smooth Scrolling
RecyclerView.LayoutManager layoutManager = new LinearLayoutManager(getApplicationContext());
adapter = new ArrayAdap(getApplicationContext(), list);
recyclerView.setLayoutManager(layoutManager);
recyclerView.setItemAnimator(new DefaultItemAnimator());
recyclerView.setAdapter(adapter);
}
}
以下是我的适配器类
public class ArrayAdap extends RecyclerView.Adapter<ArrayAdap.MyViewHolder> {
private Context context;
private List<Array_G_S> list = null;
ArrayAdapter<Array_G_S> dataAdapter;
public ArrayAdap(Context context, List<Array_G_S> list) {
this.context = context;
this.list = list;
}
@Override
public ArrayAdap.MyViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.spinner, parent, false);
return new MyViewHolder(itemView);
}
@Override
public void onBindViewHolder(ArrayAdap.MyViewHolder holder, int position) {
Array_G_S gs = list.get(position);
dataAdapter = new ArrayAdapter<String>(context,android.R.layout.simple_spinner_item,gs.getStringList());
dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
holder.spinner.setAdapter(dataAdapter);
}
@Override
public int getItemCount() {
return list.size();
}
public class MyViewHolder extends RecyclerView.ViewHolder {
Spinner spinner;
public MyViewHolder(View v) {
super(v);
spinner = (Spinner) v.findViewById(R.id.spin);
}
}