我尝试下一个:
syntax error, unexpected 'foreach' (T_FOREACH)
现在我需要添加一个新参数,但是有很多对象,我需要在foreach中使用foreach:
public class WebViewActivity extends Activity {
private WebView webView;
private ProgressDialog progress;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.webview);
WebView myWebView = (WebView) findViewById(R.id.webView1);
myWebView.setWebViewClient(new MyWebViewClient());
myWebView.loadUrl("https://www.example.com");
}
private class MyWebViewClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (Uri.parse(url).getHost().equals("https://www.example.com")) {
// This is my web site, so do not override; let my WebView load the page
return false;
}
// Otherwise, the link is not for a page on my site, so launch another Activity that handles URLs
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
return true;
}
}
}
但打印
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.checklist);
db = new DatabaseHandlerChecklist(this);
initList();
add = (ImageButton) findViewById(R.id.addChecklist);
add.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
AlertDialog.Builder add = new AlertDialog.Builder(
ChecklistActivity.this);
add.setTitle("Add checklist");
add.setIcon(R.drawable.alert_icon);
add.setMessage("Enter text : ");
final EditText content = new EditText(ChecklistActivity.this);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(
LinearLayout.LayoutParams.MATCH_PARENT,
LinearLayout.LayoutParams.MATCH_PARENT);
content.setLayoutParams(lp);
add.setView(content);
add.setPositiveButton("OK", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
String SContent = content.getText().toString();
if (SContent.equalsIgnoreCase("")) {
Toast.makeText(ChecklistActivity.this, "Insert text first !", 2000).show();
} else {
Checklist check = new Checklist(SContent, 0);
db.insert(check);
adapter.add(check);
adapter.notifyDataSetChanged();
initList();
Toast.makeText(ChecklistActivity.this, "Text added !", 2000).show();
}
}
});
add.setNegativeButton("CANCEL", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
add.show();
}
});
delete = (ImageButton) findViewById(R.id.deleteChecklist);
delete.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
db.delete();
adapter.notifyDataSetChanged();
initList();
Toast.makeText(ChecklistActivity.this, "Deleted !", 2000).show();
}
});
}
public void initList() {
list = db.getAll();
adapter = new ChecklistAdapter(this, R.layout.content_checklist, list);
ListView checklist = (ListView) findViewById(R.id.list);
checklist.setAdapter(adapter);
}
private class ChecklistAdapter extends ArrayAdapter<Checklist> {
Context context;
List<Checklist> checklist = new ArrayList<Checklist>();
int layoutResourceId;
public ChecklistAdapter(Context context, int layoutResourceId,
List<Checklist> objects) {
super(context, layoutResourceId, objects);
this.layoutResourceId = layoutResourceId;
this.checklist = objects;
this.context = context;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
CheckBox chk = null;
if (convertView == null) {
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
convertView = inflater.inflate(R.layout.content_checklist,
parent, false);
chk = (CheckBox) convertView.findViewById(R.id.checkbox);
convertView.setTag(chk);
chk.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox cb = (CheckBox) v;
Checklist changeChecklist = (Checklist) cb.getTag();
changeChecklist.setStatus(cb.isChecked() == true ? 1 : 0);
db.update(changeChecklist);
}
});
} else {
chk = (CheckBox) convertView.getTag();
}
Checklist current = checklist.get(position);
chk.setText(current.getContent());
chk.setChecked(current.getStatus() == 1 ? true : false);
chk.setTag(current);
return convertView;
}
}
@Override
protected void onDestroy() {
super.onDestroy();
db.close();
}
@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
super.onCreateOptionsMenu(menu);
MenuInflater floatMenu = getMenuInflater();
floatMenu.inflate(R.menu.float_menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch(item.getItemId()) {
case R.id.about :
Intent change = new Intent("com.interactive.writeit.ABOUT");
startActivity(change);
break;
case R.id.help :
Intent change1 = new Intent("com.interactive.writeit.HELP");
startActivity(change1);
break;
case R.id.exit :
AlertDialog.Builder exit = new AlertDialog.Builder(this);
exit.setTitle("Exit");
exit.setMessage("Are you sure want to exit ?");
exit.setPositiveButton("YES", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
finish();
}
});
exit.setNegativeButton("NO", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
exit.show();
}
return false;
}
如何在foreach中使用gallery的所有元素?
答案 0 :(得分:1)
将所有HeaderItem
项放入变量中,然后在$post->gallery->galleryMedia
变量中使用它。
$json