当前位置:网站首页>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
}
}
边栏推荐
- 42岁大厂高管,给30岁-39岁人提个醒:这6个让你变强的习惯,要尽快养成
- 同花顺股票账户开户安全吗
- LeetCode 146. LRU cache
- China's elastic belt market trend report, technical dynamic innovation and market forecast
- Analysis report on business model innovation path and operation status of China's app store industry from 2022 to 2028
- Record 5 - the serial port of stm32f411ceu6 realizes the sending and receiving of fixed length data and variable length data
- 【LeetCode】5. Longest Palindromic Substring
- Insight into China's smart medical industry in 2022
- The "fourteenth five year plan" development plan and panoramic strategic analysis report of China's information and innovation industry 2022 ~ 2028
- Use of map() function in JS
猜你喜欢

Coordinate transformation in pipelines

Mysql concat_ WS, concat function use

C language: how to give an alias to a global variable?

Colab tutorial (super detailed version) and colab pro/colab pro+ usage evaluation

Flutter库推荐Sizer 可帮助您轻松创建响应式 UI
![LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路](/img/a2/186439a6d50339ca7f299a46633345.png)
LeetCode 890 查找和替换模式[map] HERODING的LeetCode之路

MYSQL 行转列、列转行、多列转一行、一行转多列

Shardingsphere-proxy-5.0.0 deployment table implementation (I)

Summary of MySQL foundation view

Unprecedented analysis of Milvus source code architecture
随机推荐
Comprehensive analysis of C array
MOOG servo valve d634-341c/r40ko2m0nss2
[890. find and replace mode]
ASP. Net core Middleware
【LeetCode】102. 二叉树的层序遍历
Report on the "fourteenth five year plan" and strategic strategy recommendations for China's intellectual property protection industry 2022 ~ 2028
[leetcode] sword finger offer II 020 Number of palindrome substrings
JS fighting on...
[Part 7] source code analysis and application details of cyclicbarrier [key]
【LeetCode】209. Minimum length subarray
模型过拟合-解决方案(二):Dropout
Chapter 8 - shared model JUC
启牛帮开通的股票账户是安全可信的吗?
[North Asia data recovery] data recovery cases in which the partitions disappear and the partitions are inaccessible after the server reinstalls the system
年薪50万是一条线,年薪100万又是一条线…...
Use of map() function in JS
Heilongjiang Branch and Liaoning Branch of PostgreSQL Chinese community have been established!
Pytorch common parameter initialization methods: [uniform distribution, normal (Gaussian) distribution, Xavier, Kaiming, orthogonal matrix, sparse matrix, constant, identity matrix, zero filling]
The carrying capacity of L2 level ADAS increased by more than 60% year-on-year in January, and domestic suppliers "emerged"
Qrcodejs2 QR code generation JS