我正在尝试翻译我写给PHP / HMTL的Java'计算器'。为了使其起作用,必须重新初始化选择。我知道我需要使用$ _POST ['subject']来获得$ cc这对我来说会产生问题。
我尝试了几个版本,但我担心我缺乏一些基础知识。有人能够把我推向正确的方向吗?
代码不记得选项:
foreach ($subjectarray as $cc => $subject) {
echo '<option value="' . $cc . '"
if ($_POST['subject'] == $cc) echo 'selected="selected"';>' . $subject . '</option>';
}
带有记忆选项版本的代码(显然不起作用);
foreach ($subjectarray as $cc => $subject) {
echo "<option value=\"{$cc}\"";
echo ($_GET['subject'] == $cc) ? 'selected="selected"' :"";
echo ">" . $subject . "</option>";
}
另一次尝试
public class CustomAdapter extends RecyclerView.Adapter<CustomAdapter.ViewHolder> implements View.OnClickListener {
private Context context;
private List<MyData> my_data;
public CustomAdapter(Context context, List<MyData> my_data) {
this.context = context;
this.my_data = my_data;
}
@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
View itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.card,parent,false);
return new ViewHolder(itemView);
}
@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
holder.match_date.setText(my_data.get(position).getMatch_date());
holder.home_name.setText(my_data.get(position).getHome_name());
holder.away_name.setText(my_data.get(position).getAway_name());
holder.button.setId(my_data.get(position).getId());
holder.button.setTag(my_data.get(position).getStringId());
holder.button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
int intHomeGoals = Integer.parseInt(holder.edtHomeGoals.getText().toString());
int intAwayGoals = Integer.parseInt(holder.edtAwayGoals.getText().toString());
if (intHomeGoals == intAwayGoals)
{
Toast.makeText(context, "00000", Toast.LENGTH_SHORT).show();
}
}
});
Glide.with(context).load(my_data.get(position).getHome_logo()).into(holder.home_logo);
Glide.with(context).load(my_data.get(position).getAway_logo()).into(holder.away_logo);
}