我对应用程序开发很陌生,而且我很难理解如何制作可扩展的textView。我需要扩展下面的代码,该代码位于xml文件中:
<!-- Clickable title -->
<TextView android:id="@+id/help_title_guest"
//style="@style/title_help"
android:text="Title"
android:clickable="true"
android:onClick="toggle_contents"/>
<!--content to hide/show -->
<TextView android:id="@+id/txt_help_gest"
//style="@style/txt_help"
android:text="Content"/>
我需要展开help_title_guest,以便在按下help_title_guest后显示text_help来宾。链接到此xml文件的java类如下所示。
package com.example.expandinglists;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.Toast;
public class ThirdActivity extends Activity{
private final String TAG = "DemoButton";
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
//Remove TitleBar
requestWindowFeature(Window.FEATURE_NO_TITLE);
//The line below sets the convas / area labelled as activity_main
setContentView(R.layout.activity_third);
// Remove notification bar.
this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
setupMessageButton();
}
//button Class
private void setupMessageButton() {
// Button Functionality
//1. Get Reference to the button
Button messageButton = (Button) findViewById(R.id.btnOnThird);
//2. Button on Click Listener to run the button related code
messageButton.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v){
//The text below displays a message saying that The button was clicked
Log.i(TAG, "Application installed");
Toast.makeText(ThirdActivity.this,"Application Installed",Toast.LENGTH_LONG).show();
Intent startMain = new Intent(Intent.ACTION_MAIN);
startMain.addCategory(Intent.CATEGORY_HOME);
startMain.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(startMain);
}
});
}
//end of button class
}
非常感谢,
Ĵ
答案 0 :(得分:0)
如果要在两个TextView之间切换,可以将它们水平放置在彼此旁边,并在VISIBLE和GONE之间切换可见性。 GONE可见性意味着它消失并且不占用空间,这会将第二个TextView放在其位置。