为了账号安全,请及时绑定邮箱和手机立即绑定

如何可以在oncreate外面加载布局文件

如何可以在oncreate外面加载布局文件

aa868a 2015-08-08 22:12:30
package com.example.android_word;import java.util.ArrayList;import java.util.List;import org.json.JSONArray;import cn.bmob.v3.Bmob;import cn.bmob.v3.BmobQuery;import cn.bmob.v3.listener.FindCallback;import cn.bmob.v3.listener.FindListener;import com.example.android_word.Gridvew_Adater.viewHoders;import com.example.android_word.ZYType;import com.example.android_word.Gridvew_Adater;import android.support.v7.app.ActionBarActivity;import android.support.v7.app.ActionBar;import android.support.v4.app.Fragment;import android.text.SpannableString;import android.text.SpannedString;import android.text.method.LinkMovementMethod;import android.text.style.ClickableSpan;import android.annotation.SuppressLint;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.view.LayoutInflater;import android.view.Menu;import android.view.MenuItem;import android.view.View;import android.view.ViewGroup;import android.widget.AdapterView;import android.widget.AdapterView.OnItemClickListener;import android.widget.BaseAdapter;import android.widget.GridView;import android.widget.TextView;import android.widget.Toast;import android.os.Build;@SuppressLint("ShowToast")public class MainActivity extends Activity { List<ZYType> gridview_Itembeans = new ArrayList<ZYType>(); GridView gridView; Gridvew_Adater G = new Gridvew_Adater(gridview_Itembeans,this); //public class viewHoder { // TextView textView2; //}// BaseAdapter Ge = new BaseAdapter() {//// @Override// public View getView(int position, View view, ViewGroup arg2) {// // TODO Auto-generated method stub// viewHoders viewhoder;// if (view == null) {// viewhoder = new viewHoders();// view = LayoutInflater.from(getApplicationContext()).inflate(// R.layout.gridview_item, null);// viewhoder.textView2 = (TextView) view// .findViewById(R.id.textview_gridview);// view.setTag(viewhoder);// } else {// viewhoder = (viewHoders) view.getTag();// }//// viewhoder.textView2.setText(gridview_Itembeans.get(position)// .getType());// return view;//// }//// @Override// public long getItemId(int position) {// // TODO Auto-generated method stub// return position;// }//// @Override// public Object getItem(int position) {// // TODO Auto-generated method stub// return gridview_Itembeans.get(position);// }//// @Override// public int getCount() {// // TODO Auto-generated method stub// return gridview_Itembeans.size();// }// }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); gridView = (GridView) this.findViewById(R.id.gridView); gridView.setAdapter(G); selectNewsByAll(); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView<?> arg0, View view, int position, long id) { // TODO Auto-generated method stub viewHoders hoders; hoders = new viewHoders(); hoders = (viewHoders) view.getTag(); String tex1 = hoders.textView2.getText().toString(); Intent intent = new Intent(MainActivity.this, Activity1.class); intent.putExtra("tex1", tex1); startActivity(intent); } }); }    private void selectNewsByAll() { BmobQuery<ZYType> query = new BmobQuery<ZYType>("ZYType"); query.findObjects(this, new FindListener<ZYType>() { @Override public void onError(int arg0, String arg1) { Toast.makeText(MainActivity.this, "失败", 2000).show(); } @Override public void onSuccess(List<ZYType> arg0) { gridview_Itembeans.addAll(arg0); G.notifyDataSetChanged(); Toast.makeText(MainActivity.this, "成功", 2000).show(); } }); } @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here. The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml. int id = item.getItemId(); if (id == R.id.action_settings) { return true; } return super.onOptionsItemSelected(item); } /** * A placeholder fragment containing a simple view. */ public static class PlaceholderFragment extends Fragment { public PlaceholderFragment() { } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View rootView = inflater.inflate(R.layout.fragment_main, container, false); return rootView; } }}
查看完整描述

目前暂无任何回答

  • 0 回答
  • 0 关注
  • 1960 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信