创建工程后发现layout下不止有一个配置文件:activity_main fragment_main.xml,我想要添加按钮盒文本框,但是在fragment.xml
下添加后,在MainActivity.java中添加了相应的代码,后发现还是没显示出来,应该是需要在activity_main.xml中导入fragment_main.xml吧,查了半天没查到,MainActivity.java:
package com.example.ee;
import android.app.Activity;
import android.app.ActionBar;
import android.app.Fragment;
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.Button;
import android.widget.TextView;
import android.os.Build;
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView myTextview = (TextView)findViewById(R.id.myTextview);
Button myButton = (Button)findViewById(R.id.myButton);
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button");
if (savedInstanceState == null) {
getFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@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;
}
}
}
fragment_main.xml:
<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="com.example.ee.MainActivity$PlaceholderFragment" >
<TextView
android:id="@+id/myTextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello_world" />
<Button
android:id="@+id/myButton"
android:layout_width="fill_parent"
android:layout_height ="wrap_content"/>
</RelativeLayout>
activity_main.xml:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context="com.example.ee.MainActivity"
tools:ignore="MergeRootFrame">
<fragment
android:id="@+id/fragement_main"
android:name="net.loonggg.fragment.FragmentMain"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="10" />
</FrameLayout>
大家帮我看看我错在哪儿或者遗漏了什么,谢谢了!
20 个解决方案
#1
fragment.xml是按钮盒文本框的样式吗?那写个自定义的控件,控件setContentView(R.layout.fragment)
#2
我现在想知道Activity_main.xml,fragment_main.xml 中怎么写才可以加上按钮和文本控件
#3
只要在fragment_main.xml中加入按钮布局代码就可以显示了。
#4
我上面已经加进去了,不能显示,后来又在Activity_main.xml中加入了<fragment />
#5
新版安装SDK文件一开始有两个XML文件,activity_main.xml和fragment_main.xml,
不习惯的可以这样处理:
1.删除fragment_main.xml整个文件
2.对activity_main.xml,删除里面的内容。然后切换到Graphy Layout,放入一个LinearLayout就可以
3.对MainActivity.java,可以删除下面红色标注的内容,再把MainActivity extends ActionBarActivity 改为MainActivity extends Activity :
package com.zmcorp.weightcalculator;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
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.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@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);
}
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;
}
}
}
还有一种最完全的改造方法就是:把两个XML文件都删除掉,还有默认的JAVA文件也删除掉,自己重新写,当然这种方法不适合初学者。
不习惯的可以这样处理:
1.删除fragment_main.xml整个文件
2.对activity_main.xml,删除里面的内容。然后切换到Graphy Layout,放入一个LinearLayout就可以
3.对MainActivity.java,可以删除下面红色标注的内容,再把MainActivity extends ActionBarActivity 改为MainActivity extends Activity :
package com.zmcorp.weightcalculator;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
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.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@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);
}
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;
}
}
}
还有一种最完全的改造方法就是:把两个XML文件都删除掉,还有默认的JAVA文件也删除掉,自己重新写,当然这种方法不适合初学者。
#6
可以具体点吗
#7
5楼说的方法,可以,但是如果不用之前的方式,而是采用这种frame,如何修改呐?
#8
5楼 红色在哪?
#9
请问楼主解决了吗,我也遇到这个问题了,困扰好多天了
#10
我也是这个问题 楼主解决了没?
#11
myTextview,myButton是在fragment_main.xml中的,在没引进fragment_main.xml之前,你是通过findViewById找不到的。。
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);
TextView myTextview = (TextView) rootView.findViewById(R.id.myTextview);
Button myButton = (Button) rootView.findViewById(R.id.myButton);
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button")
return rootView;
}
}
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);
TextView myTextview = (TextView) rootView.findViewById(R.id.myTextview);
Button myButton = (Button) rootView.findViewById(R.id.myButton);
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button")
return rootView;
}
}
#12
在MainActivity类的内部静态类PlaceholderFragment 类中的onCreateView方法中获取fragment_main.xml中控件
/**
* 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);
Button btnFirstButton = (Button) rootView.findViewById(R.id.btn_firstButton);
btnFirstButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), "rootView.findViewById|fragment_main - -#", Toast.LENGTH_LONG).show();
}
});
return rootView;
}
}
#13
谁能告诉我那两个在activity中怎么关联的?
#14
5楼红色的在哪里呢?,急盼!
#15
5楼的红色部分是这些
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
##################################################
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
###########################################
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;
}
}
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
##################################################
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
###########################################
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;
}
}
#16
这是5楼的博客里提到的
#17
我建议按11楼的方法,把
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
/*下的这段代码
TextView myTextview = (TextView)findViewById(R.id.myTextview); //这里是找不到的
Button myButton = (Button)findViewById(R.id.myButton); //这里是找不到的
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button"); */
//去掉,然后在最后面的函数中添加实现
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);
//在这里添加实现楼主的想法
TextView myTextview = (TextView)rootView.findViewById(R.id.myTextview);
Button myButton = (Button)rootView.findViewById(R.id.myButton); //这样就能找到了
myTextview.setText("我的第一个TextView"); //这样就能生效了
myButton.setText("我的第一个Button")
//添加完毕
return rootView;
}
对应方法,View rootView = inflater.inflate(R.layout.fragment_main, container,false);
然后通过rootView 来查找findViewById(R.id.myTextview);
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
/*下的这段代码
TextView myTextview = (TextView)findViewById(R.id.myTextview); //这里是找不到的
Button myButton = (Button)findViewById(R.id.myButton); //这里是找不到的
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button"); */
//去掉,然后在最后面的函数中添加实现
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);
//在这里添加实现楼主的想法
TextView myTextview = (TextView)rootView.findViewById(R.id.myTextview);
Button myButton = (Button)rootView.findViewById(R.id.myButton); //这样就能找到了
myTextview.setText("我的第一个TextView"); //这样就能生效了
myButton.setText("我的第一个Button")
//添加完毕
return rootView;
}
对应方法,View rootView = inflater.inflate(R.layout.fragment_main, container,false);
然后通过rootView 来查找findViewById(R.id.myTextview);
#18
16楼5楼博客里文章好多,是哪一篇解决这个文体呀~能不能上个链接~多谢
#19
http://blog.sina.com.cn/s/blog_3e28c8a50101fqvw.html,5楼大大的新浪微博解决了这个问题~找到链接了~
#20
是不是你的string.xml中没有对应的<string name=""></string>
#21
#1
fragment.xml是按钮盒文本框的样式吗?那写个自定义的控件,控件setContentView(R.layout.fragment)
#2
我现在想知道Activity_main.xml,fragment_main.xml 中怎么写才可以加上按钮和文本控件
#3
只要在fragment_main.xml中加入按钮布局代码就可以显示了。
#4
我上面已经加进去了,不能显示,后来又在Activity_main.xml中加入了<fragment />
#5
新版安装SDK文件一开始有两个XML文件,activity_main.xml和fragment_main.xml,
不习惯的可以这样处理:
1.删除fragment_main.xml整个文件
2.对activity_main.xml,删除里面的内容。然后切换到Graphy Layout,放入一个LinearLayout就可以
3.对MainActivity.java,可以删除下面红色标注的内容,再把MainActivity extends ActionBarActivity 改为MainActivity extends Activity :
package com.zmcorp.weightcalculator;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
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.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@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);
}
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;
}
}
}
还有一种最完全的改造方法就是:把两个XML文件都删除掉,还有默认的JAVA文件也删除掉,自己重新写,当然这种方法不适合初学者。
不习惯的可以这样处理:
1.删除fragment_main.xml整个文件
2.对activity_main.xml,删除里面的内容。然后切换到Graphy Layout,放入一个LinearLayout就可以
3.对MainActivity.java,可以删除下面红色标注的内容,再把MainActivity extends ActionBarActivity 改为MainActivity extends Activity :
package com.zmcorp.weightcalculator;
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
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.os.Build;
public class MainActivity extends ActionBarActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
}
@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);
}
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;
}
}
}
还有一种最完全的改造方法就是:把两个XML文件都删除掉,还有默认的JAVA文件也删除掉,自己重新写,当然这种方法不适合初学者。
#6
可以具体点吗
#7
5楼说的方法,可以,但是如果不用之前的方式,而是采用这种frame,如何修改呐?
#8
5楼 红色在哪?
#9
请问楼主解决了吗,我也遇到这个问题了,困扰好多天了
#10
我也是这个问题 楼主解决了没?
#11
myTextview,myButton是在fragment_main.xml中的,在没引进fragment_main.xml之前,你是通过findViewById找不到的。。
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);
TextView myTextview = (TextView) rootView.findViewById(R.id.myTextview);
Button myButton = (Button) rootView.findViewById(R.id.myButton);
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button")
return rootView;
}
}
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);
TextView myTextview = (TextView) rootView.findViewById(R.id.myTextview);
Button myButton = (Button) rootView.findViewById(R.id.myButton);
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button")
return rootView;
}
}
#12
在MainActivity类的内部静态类PlaceholderFragment 类中的onCreateView方法中获取fragment_main.xml中控件
/**
* 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);
Button btnFirstButton = (Button) rootView.findViewById(R.id.btn_firstButton);
btnFirstButton.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
Toast.makeText(getActivity(), "rootView.findViewById|fragment_main - -#", Toast.LENGTH_LONG).show();
}
});
return rootView;
}
}
#13
谁能告诉我那两个在activity中怎么关联的?
#14
5楼红色的在哪里呢?,急盼!
#15
5楼的红色部分是这些
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
##################################################
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
###########################################
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;
}
}
import android.support.v7.app.ActionBarActivity;
import android.support.v7.app.ActionBar;
import android.support.v4.app.Fragment;
##################################################
if (savedInstanceState == null) {
getSupportFragmentManager().beginTransaction()
.add(R.id.container, new PlaceholderFragment()).commit();
}
###########################################
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;
}
}
#16
这是5楼的博客里提到的
#17
我建议按11楼的方法,把
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
/*下的这段代码
TextView myTextview = (TextView)findViewById(R.id.myTextview); //这里是找不到的
Button myButton = (Button)findViewById(R.id.myButton); //这里是找不到的
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button"); */
//去掉,然后在最后面的函数中添加实现
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);
//在这里添加实现楼主的想法
TextView myTextview = (TextView)rootView.findViewById(R.id.myTextview);
Button myButton = (Button)rootView.findViewById(R.id.myButton); //这样就能找到了
myTextview.setText("我的第一个TextView"); //这样就能生效了
myButton.setText("我的第一个Button")
//添加完毕
return rootView;
}
对应方法,View rootView = inflater.inflate(R.layout.fragment_main, container,false);
然后通过rootView 来查找findViewById(R.id.myTextview);
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
/*下的这段代码
TextView myTextview = (TextView)findViewById(R.id.myTextview); //这里是找不到的
Button myButton = (Button)findViewById(R.id.myButton); //这里是找不到的
myTextview.setText("我的第一个TextView");
myButton.setText("我的第一个Button"); */
//去掉,然后在最后面的函数中添加实现
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);
//在这里添加实现楼主的想法
TextView myTextview = (TextView)rootView.findViewById(R.id.myTextview);
Button myButton = (Button)rootView.findViewById(R.id.myButton); //这样就能找到了
myTextview.setText("我的第一个TextView"); //这样就能生效了
myButton.setText("我的第一个Button")
//添加完毕
return rootView;
}
对应方法,View rootView = inflater.inflate(R.layout.fragment_main, container,false);
然后通过rootView 来查找findViewById(R.id.myTextview);
#18
16楼5楼博客里文章好多,是哪一篇解决这个文体呀~能不能上个链接~多谢
#19
http://blog.sina.com.cn/s/blog_3e28c8a50101fqvw.html,5楼大大的新浪微博解决了这个问题~找到链接了~
#20
是不是你的string.xml中没有对应的<string name=""></string>