我试图在单击另一个textview
(较小的一个)时打开打开相应的textview(较大的一个)之前隐藏任何已打开的TextView(较大的一个)
在打开TextView
(Samller One)下相应的textview
(BiggerOne)之前,我没有像下面那样执行打开的TextView
(BiggerOne)程序。
我是Android新手,请帮助我解决此问题。
程序:
public class lessonOne extends AppCompatActivity {
Toolbar toolbar;
private CharSequence mTitle;
LinearLayout linearLayout;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_lesson_one);
//Start a new Activity on clicking the TextView
final TextView Engtxt = (TextView) findViewById(R.id.jan);
Engtxt.setOnClickListener(new View.OnClickListener(){
public void onClick(View v) {
TextView txt = (TextView) findViewById(R.id.jan);
//Define the map to iterate the visibility TextView
Map<Integer, Boolean> map = new HashMap<Integer, Boolean>();
map.put(v.getId(), FALSE);
if (map.get(v.getId()) == FALSE) {
Engtxt.setVisibility(View.GONE);
TextView titleText = (TextView) findViewById(R.id.lesOneTitle);
titleText.setVisibility(View.GONE);
LinearLayout linearLayout = (LinearLayout) findViewById(R.id.linear);
linearLayout.setOrientation(LinearLayout.VERTICAL);
/* Add textview 1 */
TextView textView1 = new TextView(lessonOne.this);
// textView1.setLayoutParams(new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT,
// LinearLayout.LayoutParams.MATCH_PARENT));
LinearLayout.LayoutParams textviewLayoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, 200);
textviewLayoutParams.setMargins(0, 9, 0, 0);
//linearLayout.addView(textView1, 1, textviewLayoutParams);
textView1.setLayoutParams(textviewLayoutParams);
textView1.setBackgroundResource(R.drawable.shapelineinsideroundedrect);
textView1.setText("JANUARY - ஜனவரி\n\nजनवरी - JANUARY - ஜனவரி");
textView1.setGravity(Gravity.TOP | Gravity.CENTER);
textView1.setTextSize(20);
textView1.setTypeface(null, Typeface.BOLD);
textView1.setPadding(0, 25, 0, 0);
textView1.setVisibility(View.VISIBLE);
linearLayout.addView(textView1, 0);
//.setContentView(linearLayout, new LinearLayout.LayoutParams(
//LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.MATCH_PARENT));
map.put(v.getId(),TRUE);
}else {
TextView extendedText = (TextView) findViewById(v.getId());
extendedText.setVisibility(View.GONE);
map.put(v.getId(),FALSE);
}
}
});
//Call the Toolbar method to set and the getTitle method to be visible
setupToolbar();
mTitle = getTitle();
}
void setupToolbar(){
toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayShowHomeEnabled(true);
}
@Override
public void setTitle(CharSequence title) {
mTitle = title;
getSupportActionBar().setTitle(mTitle);
}
}