我想将我的UI分解为几个XML布局.第一个是主要布局,其他布局是内容布局.
我想可以设置哪些content_layout应该动态地在运行时包括在内,所以我不想设定一个"layout="@+layout/content_layout"在我的XML文件.
这是我的布局:
main_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="600dp"
android:layout_height="800dp" >
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<include /> <!-- I WANT TO INCLUDE MY CONTENT HERE -->
<Button
android:id="@+id/cancelButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:text="Cancel" />
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
content_layout.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/whatever"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
content_layout2.xml:
<?xml version="1.0" encoding="utf-8"?>
<ListView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/whatever2"
android:layout_height="wrap_content"
android:layout_width="fill_parent" />
Run Code Online (Sandbox Code Playgroud)
我怎样才能做到这一点?
谢谢!
我必须在这里遗漏一些明显的东西,但我似乎无法找到任何东西让我确定MediaPlayer何时缓冲音频.我正在播放互联网音频,我想显示一个缓冲指示器,但我尝试过的任何东西都不能让我知道MediaPlayer何时中断音频缓冲,所以我无法正确显示缓冲指示器.有线索吗?
我正在尝试使用Toast内部OnCLickListener.我的代码触发以下错误:
The method makeText(Context, CharSequence, int) in the type Toast is not applicable for the arguments (new View.OnClickListener(){}, String, int)
Run Code Online (Sandbox Code Playgroud)
这是我的代码:
Button register = (Button) findViewById(R.id.register);
register.setOnClickListener(new View.OnClickListener() {
public void onClick(View arg0) {
EditText name = (EditText)findViewById(R.id.name);
String Lname = name.getText().toString();
Toast.makeText(this, Lname, Toast.LENGTH_SHORT).show();
}
});
Run Code Online (Sandbox Code Playgroud) 我已经读过我们只能通过继承它来实例化一个抽象类,但我们不能直接实例化它.
但是,我看到我们可以通过调用另一个类的方法来创建一个具有抽象类类型的对象.
例如 - LocationProvider是一个抽象类,我们可以通过调用类中的getProvider()函数来实例化它LocationManager:
LocationManager lm = getSystemService(Context.LOCATION_PROVIDER);
LocationProvider lp = lm.getProvider("gps");
Run Code Online (Sandbox Code Playgroud)
抽象类如何在这里实例化?
我需要在Alert Dialog中显示多行文本.如果我使用多个setMessage()方法,则只显示最后一个setMessage,如下所示.
final AlertDialog alertDialog = new AlertDialog.Builder(this).create();
alertDialog.setTitle("Statistics:");
alertDialog.setMessage("No. of attempts: " + counter);
alertDialog.setMessage("No. of wins: " + counterpos);
alertDialog.setMessage("No. of losses: " + counterneg);
Run Code Online (Sandbox Code Playgroud)
有没有办法在对话框中为每个这些创建一个新行?就像在System.print.out()中使用\n; 方法.
谢谢!
我需要在ListView选中的一行中突出显示一行(向用户显示他选择的内容),因此,这不是将要选择的那一行,而是他之前选择的那一行.
我已经有了以下位置:
ListView.setSelection(position);
Run Code Online (Sandbox Code Playgroud)
现在我想要的是选择这个特定的行并突出显示它.
onCreate()活动中包含以下内容的代码ListView:
public class CountryView extends Activity
{
protected static final String LOG_TAG = null;
/** Called when the activity is first created. */
String[] lv_arr = {};
ListAdapter adapter;
TextView t;
private ListView lvUsers;
private ArrayList<Coun> mListUsers;
String responce=null;
public int d;
int selectedListItem = -1;
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.country);
Intent data =getIntent();
mListUsers = getCoun();
lvUsers = (ListView) findViewById(R.id.counlistView);
lvUsers.setAdapter(new ListAdapter(this, R.id.counlistView, mListUsers));
selectedListItem=data.getExtras().getInt("PositionInList");
lvUsers.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
lvUsers.setOnItemClickListener(new …Run Code Online (Sandbox Code Playgroud) 我试图在两个活动之间传递一个字符串.我在其他项目中使用相同的方法完成了这个,但由于某种原因,当我调用intent.getStringExtra(String)时,我得到一个NullPointerException.我也试过通过创建一个Bundle for extras
Bundle b = getIntent().getExtras();
Run Code Online (Sandbox Code Playgroud)
但那也返回了null.下面是我目前正在尝试使用的代码.
活动A:
Intent myIntent = null;
String select = "";
if (selection.equals("Chandelle")) {
myIntent = new Intent(Commercial.this, Chandelle.class);
select = "Chandelle";
} else if (selection.equals("Eights on Pylons")) {
myIntent = new Intent(Commercial.this, EightsOnPylons.class);
select = "Eights on Pylons";
}
// Start the activity
if (myIntent != null) {
myIntent.putExtra("selection", select);
Log.d("*** OUTBOUND INTENT: ", "" + myIntent.getExtras().get("selection"));
startActivity(myIntent);
}
Run Code Online (Sandbox Code Playgroud)
这是活动B中试图拉出额外内容的代码:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Intent i = getIntent();
if (i == …Run Code Online (Sandbox Code Playgroud) 在我的应用程序中有一个按钮(activity1).当用户点击它时我想在游戏中没有声音.我想我应该通过在按钮的onClick方法中使用activity1中的sharedpreferences来做到这一点:
SharedPreferences.Editor editor = mPrefs.edit();
editor.putString("sound","1");
editor.commit();
Run Code Online (Sandbox Code Playgroud)
声音和游戏从另一个活动(activity2)开始.我需要在那里阅读set sharedpreferences,但我不知道该怎么做.
谢谢
编辑
我已经离开了这条线:
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(Activity1.this);
Run Code Online (Sandbox Code Playgroud)
根据您在Activity2.class中的帮助,我读了这样的首选项:
SharedPreferences myPrefs = getSharedPreferences("Activity1", MODE_PRIVATE); //Activity1.class
String ifsound = myPrefs.getString("sound","");
if (ifsound.equals("1"))
{
Toast.makeText(Activity1.this, "1", Toast.LENGTH_LONG).show();
}
else
{
Toast.makeText(Activity1.this, "0", Toast.LENGTH_LONG).show();
}
Run Code Online (Sandbox Code Playgroud)
我有这个困难,我的圆角和背景图像LinearLayout.
我知道我可以通过使用形状绘制XML achive圆角,但是如果我把形状绘制作为我的背景LinearLayout有android:background=@drawable/rounded_corner那么我不能将任何图像作为背景.
如何在LinearLayout中同时获得带有背景图像的圆角?任何帮助,将不胜感激.谢谢!
我有一个自定义ViewSwitcher,我实现了触摸事件,所以我可以使用触摸屏滚动屏幕.
我的布局层次结构如下所示:
<ViewSwitcher>
<LinearLayout>
<ListView />
</LinearLayout>
<LinearLayout>
<ListView />
</LinearLayout>
</ViewSwitcher>
Run Code Online (Sandbox Code Playgroud)
现在,问题是触摸事件正被消耗
ListViews,我无法切换视图.当我没有时,它工作正常ListViews.我需要能够滚动浏览视图并滚动查看ListView.
我该如何解决这个问题?
编辑:我还需要ListView可点击的项目.
提前致谢!