对于我的应用程序我在这里创建FAQ页面我使用2个布局(一个用于问题,另一个用于答案)和1个活动我有4个问题和答案我的布局编码
问题
<TextView
android:id="@+id/qus1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="How does ringee™ works?"
android:textColor="@color/black"></TextView>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/qus2"
android:text="Can I choose event places among the town/city localities?"
android:textColor="@color/black"/>
<TextView
android:id="@+id/qus3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="When the reminder message will be sent to his/her invites?"
android:textColor="@color/black"/>
<TextView
android:id="@+id/qus4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Is the reminder message customizable?"/>
获得答案
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ans1"
android:text="ringee™ provides platform to send reminder messages for your occasions , where in you can manage your occasion, your invites list and more features coming in near future. ringee™ is your one stop solution to manage your occasions and it can't be that easy before.
All you have to do is :-
Create occasion types like Marriage, Party, Birthday, Anniversary Celebrations.
Add invites list whom you want them invited.
Select reminder days (On Event Day, 2 Days Before, Week Before) and activate."
android:textColor="@color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ans2"
android:text="no ringee™ does'nt have this functionality, it will be soon available to the users"
android:textColor="@color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ans3"
android:text="ringee™ send reminder messages to invites at 10 AM Indian Standard Time[IST] on a day. This is routine task and will be send every day at 10 AM IST"
android:textColor="@color/black"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/ans4"
android:text="Users are given option to customize event text, but not event place and date and time of the event."
android:textColor="@color/black"/>
我的活动代码是
public class AboutActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.about);
TextView faq = (TextView) findViewById(R.id.faq);
faq.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
setContentView(R.layout.faq_activity);
}
});
}
}
(上面的代码只显示了一页中的4个问题) 在这里,我在页面中显示4个问题,当用户点击一个问题时,我必须在该问题下显示相应的答案,并且当他们点击其他地方时应该关闭
任何人都可以帮助我完成这项功能吗?
答案 0 :(得分:0)
您应该使用ExpandableListView而不是将每个项目添加到列表中
答案 1 :(得分:0)
走这条路
将一个垂直LinearLayout
作为根布局。
在LinearLayout内部需要8 Textview
s。 4个问题,4个答案。
8个textviews的顺序应该是que1,ans1,que2,ans2 .....
现在将4个答案文字视图的可见性设置为已消失。
现在以编程方式对4个问题文本视图中任意一个的点击事件设置相应的答案可见性。
并将onTouchListener
添加到父LinearLayout并在onTouchListener内设置答案textviews visibility to GONE
设置答案textView可见性如下
<TextView
android:id="@+id/answer1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"/>
以编程方式更改可见性使用此
answer1.setVisibility(View.GONE);