当前位置:网站首页>Hongmeng starts
Hongmeng starts
2022-06-12 23:09:00 【And white】
Related articles
If you set the layout file
Folder for layout files src-main-resources-layout Created in xml file
onstart Set the layout file in
public class MainAbility extends Ability {
private ListContainer listView;
@Override
public void onStart(Intent intent) {
super.onStart(intent);
// Set up layout file
super.setUIContent(ResourceTable.Layout_main_slice);
// In Android findviewById
listView = (ListContainer) findComponentById(ResourceTable.Id_listView);
}
@Override
public void onStop() { super.onStop(); }
}
How to follow android Get elements as well (findviewbyid)
similar findviewById operation
Button button = (Button) findComponentById(ResourceTable.Id_button);
Click event
button.setClickedListener(new Component.ClickedListener() {
public void onClick(Component v) {
// TODO anything
}
});
Set to enter app The default interface of be-all ability There can only be one of them
{
"skills": [
{ "entities": ["entity.system.home"],
"actions": [ "action.system.home"] }
],
"orientation": "unspecified",
"name": "com.example.helloworld.ability.LoginAbility",
"icon": "$media:icon",
"description": "$string:loginability_description",
"label": "$string:entry_LoginAbility",
"type": "page",
"launchType": "standard"
}
List containers ListContainer Use
<ListContainer ohos:id="$+id:listView" ohos:height="match_parent" ohos:width="match_parent"/>
public class MainAbility extends Ability {
private ListContainer listView;
List<Enter> enterList = new ArrayList<>();
@Override
public void onStart(Intent intent) {
super.onStart(intent);
super.setUIContent(ResourceTable.Layout_main_slice);
initData();
initListView();
}
private void initListView() {
listView = (ListContainer) findComponentById(ResourceTable.Id_listView);
CustomItemProvider adapter = new CustomItemProvider();
adapter.setList(enterList);
listView.setItemProvider(adapter);
}
private void initData() {
enterList.add(new Enter(" Zhang San ", 18));
enterList.add(new Enter(" Li Si ", 24));
enterList.add(new Enter(" Hu Hansan ", 60));
enterList.add(new Enter(" Zhang San ", 18));
enterList.add(new Enter(" Li Si ", 24));
enterList.add(new Enter(" Hu Hansan ", 60));
enterList.add(new Enter(" Zhang San ", 18));
enterList.add(new Enter(" Li Si ", 24));
enterList.add(new Enter(" Hu Hansan ", 60));
enterList.add(new Enter(" Zhang San ", 18));
enterList.add(new Enter(" Li Si ", 24));
enterList.add(new Enter(" Hu Hansan ", 60));
}
// amount to android Adapter in
class CustomItemProvider extends BaseItemProvider {
List<Enter> enterList;
public void setList(List<Enter> enterList) { this.enterList = enterList; }
@Override
public int getCount() { return enterList.size(); }
@Override
public Object getItem(int i) { return enterList.get(i); }
@Override
public long getItemId(int i) {return 0; }
@Override
public Component getComponent(int i, Component component, ComponentContainer container) {
ViewHolder holder = null;
if (component == null) {
component = LayoutScatter.getInstance(container.getContext()).parse(ResourceTable.Layout_item_main, container, false);
holder = new ViewHolder();
holder.name = (Text) component.findComponentById(ResourceTable.Id_name);
holder.age = (Text) component.findComponentById(ResourceTable.Id_age);
component.setTag(holder);
} else {
holder = (ViewHolder) component.getTag();
}
holder.name.setText(enterList.get(i).getName());
holder.age.setText(enterList.get(i).getAge());
return component;
}
class ViewHolder {
Text name;
Text age;
}
}
class Enter {
String name;
int age;
//..get set How to achieve it
}
}
边栏推荐
- Research Report on truffle fungus industry - market status analysis and development prospect forecast
- The programmer has worked for 7 years. At the age of 31, he has no choice but to deliver takeout. I really don't want you to go through his journey again
- China's elastic belt market trend report, technical dynamic innovation and market forecast
- Ten key defensive points in the detailed attack and defense drill
- Colab教程(超级详细版)及Colab Pro/Colab Pro+使用评测
- Inventory of CV neural network models from 2021 to 2022
- Hostvars in ansible
- iShot
- Pytorch中的梯度累加【在实验时,由于GPU显存限制,遇到batch_size不能再增大的情况。为解决该问题,使用梯度累加方法】
- ImageView grayed, reflected, rounded, watermarked
猜你喜欢
Huawei officially entered the "front loading" stage, and the millimeter wave radar track entered the "localization +4d" cycle
LeetCode 146. LRU cache
80 lines of code to realize simple rxjs
Inventory of CV neural network models from 2021 to 2022
Insight into China's smart medical industry in 2022
【建议收藏】通俗易懂图解网络知识-第一篇
The most widely used dynamic routing protocol: OSPF
【Web技术】1348- 聊聊水印实现的几种方式
Chapter 8 - shared model JUC
2022 heavyweight: growth law - skillfully use digital marketing to break through enterprise difficulties
随机推荐
【建议收藏】通俗易懂图解网络知识-第一篇
自动获取结构体内部成员变量的位置偏移
VIM use the lower right 4 keys
Research and Analysis on the development of China's Melamine Industry from 2022 to 2028 and market prospect forecast report
PHP deletes data of the same item in a two-dimensional array
Web3 principle and decentralization
模型过拟合-解决方案(二):Dropout
[web technology] 1348- talk about several ways to implement watermarking
[Part VI] source code analysis and application details of countdownlatch [key]
Analysis report on the "fourteenth five year plan" and the latest development trend of China's medical information industry from 2022 to 2028
Unprecedented analysis of Milvus source code architecture
Summary of MySQL foundation view
MYSQL 行转列、列转行、多列转一行、一行转多列
同花顺股票账户开户安全吗
Dix points de défense clés dans les exercices d'attaque et de défense détaillés
Use js to listen for Keydown event
[recommended collection] easy to understand graphic network knowledge - Part 1
China's new generation information technology industry "14th five year plan" special planning and innovation strategic direction report 2022 ~ 2028
Introduction to Quaternion
Lua loop statement